Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch Emacsclient with GUI (from Dock) on Mac OS X

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.

like image 499
Mekeor Melire Avatar asked Sep 13 '16 08:09

Mekeor Melire


People also ask

Is Emacs available for Mac?

Emacs can be installed on MacOS using Homebrew. The Emacs for OSX website also provides universal binaries.


1 Answers

From the terminal

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 ""


From macOS GUI

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.


From anywhere, flexibly

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.

like image 145
Braham Snyder Avatar answered Sep 28 '22 08:09

Braham Snyder