Fork me on GitHub
#emacs
<
2023-02-01
>
J11:02:45

Hi guys! Anyone use emacs as daemon on MacOs? I created a launchctl file:

<?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
  <plist version="1.0">
    <dict>
      <key>Label</key>
      <string>gnu.emacs</string>
      <key>ProgramArguments</key>
      <array>
        <string>/opt/homebrew/bin/emacs</string>
        <string>--daemon</string>
      </array>
      <key>RunAtLoad</key>
      <true/>
      <key>StandardErrorPath</key>
      <string>/tmp/gnu-emacs-daemon.log</string>
      <key>StandardOutPath</key>
      <string>/tmp/gnu-emacs-daemon.log</string>
      <key>UserName</key>
      <string>Foo</string>
    </dict>
  </plist>
The daemon start correctly. According the log file and the process:
Starting Emacs daemon.
Doom loaded 187 packages across 35 modules

$ ps aux | grep emacs
=> 751   0.0  0.7 409481952 121056   ??  Ss   12:16PM   0:03.64 /opt/homebrew/Cellar/emacs-plus@28/28.1/Emacs.app/Contents/MacOS/Emacs --bg-daemon=\0123,4\012
But when I use the emacsclient I get: emacsclient: can't find socket; have you started the server? Any advice?

Benjamin C11:02:04

I presume you already have this somewhere in your config?: (server-start) Not sure if you need that with --bg-daemon, but might be worth a shot.

elken12:02:18

emacs-plus already comes with one you can start with brew services start (the install tells you about it iirc)

César Olea14:02:05

As @U043RSZ25HQ said if you’re using emacs-plus it already comes with its own service that you can start with brew services start d12frosted/emacs-plus/emacs-plus or if you use a specific branch: brew services start d12frosted/emacs-plus/emacs-plus@28 adjust accordingly. If you still want to use launchctl change --daemon to --fg-daemon and once its running to connect the client run /opt/homebrew/bin/emacsclient -c I currently run it via homebrew, but used to do it through launchctl in the past.

J14:02:11

Thanks guys! I will try that.