Macos – How to run Mac OSX graphical Emacs in daemon mode

emacsmacos

Short form: I want to run the Mac OSX version of Emacs found on
http://emacsformacosx.com/ as a daemon, with graphical and text clients
connecting to it as-needed.

In detail, here is the workflow I want:

  1. On login, run /Applications/Emacs.app/Contents/MacOS/Emacs --daemon to start emacs as a daemon. I already know how to do this.

  2. When running emacs from a local termnal, I want Either one of these:

    1. If I run emacs from a local command prompt, open a new frame with the selected file.
    2. If #1 is not possible, at least if I run emacsclient from the command line, open a new frame with the selected file.
  3. When running emacs from a remote terminal, I would like a text-mode emacs to start, connected to the daemon process.

  4. If I run Emacs.app re-use the emacs daemon that is running in the background instead of starting a new instance and open a new window on it.

So far, I am able to accomplish only #1 and #2.2 above, but those are the easy parts. #3 and #4 are the things that are most needed in order to make this work. Does anyone know how to accomplish these things?

Best Answer

  1. You've got this handled
  2. Yes, you'll want to use emacsclient. To get a new frame, add the -c option. I have an alias to make it quicker and to tell emacsclient not to wait for emacs server to return:

    alias em='emacsclient -n'
    
  3. emacsclient -nw
  4. I'm not sure about this. I start Emacs once and always load new files either within emacs or using my em alias.

Update:

Check out this tip documenting how to use Platypus to create an app wrapper around emacsclient. You could then use "Open With..." to launch using your new app wrapper.