I wrote a little zsh function to allow me to run emacs from the command-line:

function emacs() {
    /Applications/Emacs.app/Contents/MacOS/Emacs $@ &

This works perfectly, but it seems to start emacs as the last window in my Cmd-tab list. Is there any way to make it take focus when it's started?


The emacs way to open files into emacs is to use emacsclient from the command line. This requires that emacs is running the emacs server (using M-x server-start or put (server-start) into your .emacs file).

I've got this in my .bashrc (adapt for zsh as appropriate):

alias em='emacsclient -n'

I'm running GNU Emacs (built from CVS last week sometime) and this version brings my emacs window to front.

If you're opening and exiting emacs for each file you edit, you're not taking full advantage of emacs' possibilities. I typically start emacs shortly after a reboot and it stays open until the next Mac software update requires a reboot.

open -a Emacs.app foo.txt

This will open the file "foo.txt" in Emacs.app. If you want to send command arguments to Emacs, use the args switch.

  • The problem with this is that I was intending the command-line options ($@) to go to emacs. With this approach, they go to open. – Jason Baker Nov 21 '09 at 18:00
  • Scratch that. Apparently this does work if you invoke emacs like this: open -a /Applications/Emacs.app/Contents/MacOS/Emacs --args $@ – Jason Baker Nov 21 '09 at 18:01
  • I thought the arguments were files you intended to open with the One True Editor. If not, then yes, you need the '--args' switch. – Richard Hoskins Nov 21 '09 at 19:43
  • Hey Jason...did you figure out any way to get this to work without using the open command? – Das Sep 19 '11 at 21:04
  • Actually nevermind. I think I can live with using that open command even though I think it is lame and reminiscent of kindergarten. – Das Sep 19 '11 at 21:06

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.