Skip to content

Instantly share code, notes, and snippets.

@redinger
Created November 26, 2011 03:22
Show Gist options
  • Save redinger/1394910 to your computer and use it in GitHub Desktop.
Save redinger/1394910 to your computer and use it in GitHub Desktop.
Setting up Emacs daemon on OS X

Setting up Emacs daemon on OS X

Tired of waiting for emacs to start on OS X? This step by step guide will teach you how to install the latest version of emacs and configure it to start in the background (daemon mode) and use emacsclient as your main editor.

Install Cocoa Emacs

Download the latest pretest version of [Emacs for Mac OS X]: http://emacsformacosx.com/builds

Drag the Emacs Application to your Applications folder

Create the daemon application

Open the AppleScript editor and paste the following:

tell application "Terminal"
do shell script "/Applications/Emacs.app/Contents/MacOS/Emacs --daemon"
end tell

Save this as an Application called "Emacs Daemon" in your Applications folder

Add as a login item

Goto System Preferences > Accounts

  • With your user name selected, click on the Login Items tab
  • Click on the plus sign
  • Browse to your applications folder and find "Emacs Daemon"
  • Don't worry about the "hide" checkbox, since it the dock icon disappears naturally

Create the client application

Open the AppleScript editor and paste the following:

tell application "Terminal"
try
set frameVisible to do shell script "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -e '(<= 2 (length (visible-frame-list)))'"
if frameVisible is not "t" then
do shell script "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -c -n"
end if
on error
do shell script "/Applications/Emacs.app/Contents/MacOS/Emacs --daemon"
do shell script "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -c -n"
end try
end tell
tell application "Emacs" to activate

Save this as an Application called "Emacs Client" in your Applications folder.

Giving the client application a proper icon

Using the Finder, navigate to your Application folder and right click on your Emacs application (not the client or daemon), and click on Show Package Contents Do the same for the Emacs Client application

Copy the Emacs.icns file from Contents/Resources of the Emacs application to the Contents/Resources of the Emacs Client application Delete applet.icns and rename Emacs.icns to applet.icns in the Emacs Client application.

@freizl
Copy link

freizl commented Mar 26, 2024

Im using brew installed emacs-plus and use brew services to start the emacs as service.
By default, it does start as foreground application. I changed it background daemon by edit this file directly.

/opt/homebrew/Cellar/emacs-plus@29/29.3/homebrew.mxcl.emacs-plus@29.plist

Looking for this section

<key>ProgramArguments</key>
<array>
  <string>/opt/homebrew/opt/emacs-plus@29/bin/emacs</string>
  <string>--daemon</string>
</array>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment