How can I launch Emacsclient with GUI from the Dock (or maybe also from the terminal) on Mac OS X?
The EmacsWiki describes how to create an "Emacs from Dock" app using Automator. It worked for me but I don't want to launch Emacs but Emacsclient. So, I tried replacing /Applications/Emacs.app/Contents/MacOS/Emacs
with both /Applications/Emacs.app/Contents/MacOS/bin/emacsclient
and /Applications/Emacs.app/Contents/MacOS/bin/emacsclient -c
but both didn't work.
Emacs can be installed on MacOS using Homebrew. The Emacs for OSX website also provides universal binaries.
You can find the appropriate path to emacsclient
using type
in your shell (assuming emacsclient -c
works from said shell):
$ type emacsclient
emacsclient is /usr/local/bin/emacsclient
Then we can add the appropriate emacsclient flags (see $ man emacsclient
for details) to open the GUI:
/usr/local/bin/emacsclient -n -c -a ""
To launch emacsclient
from eg the Dock or Spotlight, it's easy to use Automator. Automator is built in to macOS.
Choose to make an "Application", then choose "Run Shell Script", and add a modified version of the above call to emacsclient
:
/usr/local/bin/emacsclient -n -c -a "" -- "$@"
Then change "Pass input": use "as arguments" instead of "to stdin".
The added "$@"
is where any optional arguments passed to this shell script will be placed. Here, this allows you to pass a filename to open with emacsclient
. Automator automates passing this filename in when, eg, you click to open a file with the application we've just made. This also allows you to set the application to be the default application for certain file types.
Another way to run the above shell command is with skhd
(link). skhd
is far more involved to learn, but ultimately makes it much easier to set up a large number of shell commands with rapid access.
For example, you could make "Ctrl-o" from anywhere in macOS enter a mode you name open_app
, from which you could press "e" to open emacsclient
, "d" to open emacs --debug-init
, "t" to run emacs --adv-timers
, "f" to open Firefox, "F" to open a second Firefox profile, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With