You can do the -a ''
thing with emacsclient
but what I do and a lot of people do is to have some kind of script that basically does what emacsclient ''
does in multiple steps.
My version is something like this BASH script: The part you are interested in is the ensure-server-is-running
function. This is the "main function" of the script, what follows is the ensure-server-is-running
function and the rest is there after that for your curiosity but does not contribute to answering the question.
#!/bin/bash
# ec.sh
#
# [function definitions]
#
ensure-server-is-running
ensure-frame-exists
focus-current-frame
Ensuring that the server is running
# ec.sh function definition
# From https://emacs.stackexchange.com/a/12896/19972
function server-is-running() {
emacsclient -e '(+ 1 0)' > /dev/null 2>&1
}
function ensure-server-is-running(){
if ! server-is-running ; then
echo "Need to start daemon, press enter to continue, C-c to abort"
read
emacs --daemon
fi
}
And the other two function:
# ec.sh function definition
# From https://superuser.com/a/862809
function frame-exists() {
emacsclient -n -e "(if (> (length (frame-list)) 1) 't)" 2>/dev/null | grep -v nil >/dev/null 2>&1
}
function ensure-frame-exists() {
if ! frame-exists ; then
emacsclient -c --no-wait
fi
}
# From https://emacs.stackexchange.com/a/54139/19972
function focus-current-frame() {
# Doesn't work a frame exists and is in a terminal
emacsclient --eval "(progn (select-frame-set-input-focus (selected-frame)))"
}
focus-current-frame
is something that will make the OS put you in the current Emacs Frame. This is the most important feature. For me I insert an adapted version of this into a MacOS Automator app. When there is an emacs GUI frame, doing Spotlight Search "EmacsC" (usually just typing the "e" is enough), puts me in my emacs window. It's a super fast way of switching to an emacs window.