I am currently running Emacs as a desktop with EXWM. And I am trying to run some apps on startup to see them in a EXWM's systemtray:

(defun run-auto-start ()
   (start-process-shell-command "pnmixer" nil "/bin/pnmixer")
   (start-process-shell-command "nm-applet" nil "/bin/nm-applet"))

I have attached this function to exwm-init-hook. But it seems that it is too early for a system tray to work properly, because sometimes these apps do not appear in a systemtray or only one of them does. (I initialize systemtray with (exwm-systemtray-enable) before attaching the function to the hook) However if I evaluate those two lines manually after Emacs finished loading, pn-mixer and nm-applet immediately launch and go to the system tray.

So what is the last Emacs initialization hook I can use to execute my shell commands as late as possible to avoid running them manually? Maybe there is some hack to emulate this kind of "late hook"?..

P.S. I have tries after-init-hook and emacs-startup-hook none of them work well

  • 1
    I launch nm-applet from my .xsession before firing emacs and so exwm. The app appears in the exwm sys-tray just fine. Commented Jul 25, 2022 at 21:29
  • (Untested) Make sure that you enable the systemtray (with exwm-systemtray-enable) before you add your function to exwm-init-hook and make sure that you add your function to the hook with a DEPTH parameter of 100 to make sure that it is added after the systemtray init function that exwm-systemtray-enable adds. Check the value of exwm-init-hook to make sure you have done it correctly.
    – NickD
    Commented Jul 26, 2022 at 2:42
  • Fran, didn't work for me, anyway I wanted to have some portable solution inside of my Emacs config, so that I do not need to borrow X configs to run Emacs on another machine Commented Jul 26, 2022 at 19:30

1 Answer 1


Refer to C-hig (elisp)Startup Summary RET

P.S. I have tries after-init-hook and emacs-startup-hook none of them work well

The only startup hook which runs after emacs-startup-hook is window-setup-hook:

This is very similar to ‘emacs-startup-hook’.  The only difference
is that this hook runs after frame parameters have been set up in
response to any settings from your init file.  Unless this matters
to you, use ‘emacs-startup-hook’ instead.  (The name of this hook
is due to historical reasons, and does not reflect its purpose
very well.)

If that (window-setup-hook) doesn't work either, you could use one of the startup hooks to start a timer via run-with-timer, so that your code runs after some brief delay.

  • But EXWM still starts up after emacs-startup-hook, so exwm-init-hook runs after window-setup-hook? run-with-timer solved the problem ! thanks Commented Jul 26, 2022 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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