How to launch GUI Emacs from command line in OSX?

In your shell, alias the command 'emacs' to point to the OSX emacs application

In my shell (running the default bash), I have the following (in my .bashrc)

alias emacs='open -a /Applications/Emacs.app $1'

Then, typing emacs on the command line starts the emacs application.

I would, however, recommend that you open a copy of emacs and just keep it up and running. If that's the case, and you want to load a file into an existing copy of emacs, you can use the emacsclient by placing the following in your .bashrc:

alias ec='/Applications/Emacs.app/Contents/MacOS/bin/emacsclient'

Then add the following to your .emacs file to start the emacs server (which receives the emacsclient calls)

;;========================================
;; start the emacsserver that listens to emacsclient
(server-start)

Then you can type

ec .bashrc

to load a copy of .bashrc into an existing emacs session!


Call the following script "emacs" and put it in your PATH somewhere:

#!/bin/sh
/Applications/Emacs.app/Contents/MacOS/Emacs "$@"

That covers #2, #3, and #4.

For #1, put this somewhere in your .emacs file:

(x-focus-frame nil)

The emacsformacosx.com site now has a How-To page, which is where the top snippet came from. There's more info there about running emacsclient and hooking Emacs up to git mergetool.


This improves on David Caldwell's answer by starting Emacs in the background:

#!/bin/sh
$(/Applications/Emacs.app/Contents/MacOS/Emacs "$@") &

As stated in the other answer, this covers #2, #3, and #4. For #1, put this somewhere in your .emacs file: (x-focus-frame nil).

Note that the following does not work for me -- it does not start Emacs in a directory specified on the command line (e.g. emacs .)

# NOT RECOMMENDED
#!/bin/sh
/Applications/Emacs.app/Contents/MacOS/Emacs "$@" &