Making emacsclient a default editor on Mac

I had a few problems with making EmacsClient my default way of opening files on Mac.

Firstly just add (server-start) to your emacs init file.

Secondly, emacsclient launched from terminal uses “wrong” emacsclient. Use one from/Applications/Emacs.app/Contents/MacOS/bin instead one from /usr/bin . For example add symlink to /usr/local/bin and remember to have /usr/local/bin before /usr/bin in $PATH.

Now we can launch files using emacsclient from shell – just do “emacsclient filename”.

Add these two lines to your .bash_profile:

export EDITOR=emacsclient
export VISUAL=$EDITOR

Sadly, you can’t tell finder “use this shell command to open this file”. Mac OS X can only use .app for this. I found two .apps that were aiming to do this, but both of them didn’t work at all for me.

The solution which finally worked for me was creating Automator app. Open Automator and click File->New and choose “Application”. Then, from menu on the left choose “Run Shell Script”. Change Pass input from “to stdin” to “as arguments”. Then add following code:

for f in "$@"
do
	emacsclient --alternate-editor="" -n "$f"
done

Now click File->Export and save it in Applications folder.

Now the only thing left is to make this editor default for Finder. For files that have some extension you can change default program using finder. Right click file and then click get info. In section “Open with” change to EmacsClient.app and click “Change All”.

For files without extension you can change default program using RCDefaultApp . After installing it you will have section “Default Apps” in System Preferences pane. I’ve set EmacsClient as default app for all Mime types that look textish and for UTI public.data . It works so far.

It requires that emacs is running at the time, but since I always have Emacs open I didn’t feel compelled to investigate how to work around it.

I used Emacs.app 24.3 and OS X 10.9 .

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s