MacOS – On OS X, how to start Cocoa emacs *and* bring it to front

cocoaemacsmacosshell-scriptzsh

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?

Best Answer

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 23.1.50.5 (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.

Related Question