I'm curious what you're ultimately trying to accomplish? Why not just always
start a new Emacs process? The additional overhead would be a small fraction of a second
On my 2 year old MBP:
% time emacs --batch --eval nil
emacs --batch --eval nil 0.03s user 0.01s system 87% cpu 0.054 total
Going down your current path, you can check the exit code from emacsclient
to decide if you should run in batch
if emacsclient --eval nil >/dev/null 2>&1; then echo "run client"; else echo "run emacs"; fi
EDIT: I see you want to script an answer to the lock stealing question. Check
out my answer to this question for using ask-user-about-lock
to solve this.
EDIT: So the idea is to redefine ask-user-about-lock
to return t. See docs:
ask-user-about-lock is an autoloaded Lisp function in `userlock.el'.
(ask-user-about-lock FILE OPPONENT)
Ask user what to do when he wants to edit FILE but it is locked by OPPONENT.
This function has a choice of three things to do:
do (signal 'file-locked (list FILE OPPONENT))
to refrain from editing the file
return t (grab the lock on the file)
return nil (edit the file even though it is locked).
You can redefine this function to choose among those three alternatives
in any way you like.
[back]
script example (remember to chmod)
#!/usr/bin/env emacs --script
(defun ask-user-about-lock (file opponent)
t)
(org-mobile-pull)
(org-mobile-push)