source : Creating universal Emacs Lisp packages and scripts | DanPetrov
You can add a [[shebang]] to the top of an [[Emacs Lisp]] script to have it evaluated in batch mode:
#!/usr/bin/env emacs --script
Secondly, you can determine if a script is running in batch mode with the following predicate:
(defun foo-running-as-script-p ()
"Return truthy if running as Elisp script."
(member "-scriptload" command-line-args))
Finally, it’s worth adding some kind of “main” function:
(defun main ()
"Entrypoint for foo"
(pprint command-line-args-left)
(message "Do stuff here"))
(when (foo-running-as-script-p)
(main))