I just started using erc in emacs and I've built emacs with --with-dbus compile option. I enabled notifications (so that I can get a notifications when my erc nickname gets mentioned) module in Erc modules list. But, whenever my nick gets mentioned in an erc channel, dbus gives me this error message:Error: (dbus-error "No connection to bus" :session). I've no idea how to fix this :(

How can I get notifications to work for macOS?

Edit: I've started the dbus process with: brew services start dbus

  • Is there an application you need to run to convert dbus messages to macOS notifications? BTW, you can create notifications using the "display" shell command. I'd imagine there's some way to get erc to use that instead of dbus, but I don't know.
    – Alan Third
    Commented Dec 1, 2016 at 13:09
  • @AlanThird I found out how to get notifications from ERC nick mentions via terminal-notifier. It sends notifications to the notification centre. A reddit user pointed out the solution. I'm waiting for him to write an answer here. Commented Dec 1, 2016 at 13:51
  • 1
    @AlanThird This is the reddit thread about this discussion Commented Dec 1, 2016 at 13:56
  • One option would be to set up an applescript inside an elisp function and have it run whenever needed, similar to the answer in the related thread on reddit re erc-terminal-notifier.el. You can Google emacs applescript for some ideas of how to do this, and you'll need to decide what you want the applescript to do -- e.g., display a notification; or, say "Hello, you've got a message".
    – lawlist
    Commented Dec 1, 2016 at 17:03
  • @lawlist, Ahh I am not too sure I'd want to spend time doing all that. I know nothing about apple script. I guess I'll just stick to using terminal-notifier. It was awfully simple to setup and use. Thanks for the info though. Commented Dec 1, 2016 at 17:45

3 Answers 3


Another way is to use the ns-do-applescript elisp function:

(ns-do-applescript "display notification \"hello world\"")


(ns-do-applescript "display notification \"hello world\" with title \"some title\"")

to run AppleScript from Emacs.

More info on what commands are available in AppleScript:



Thanks to jbornhold answer in this reddit discussion, I was able to enable notifications for erc nick mentions.

Here's how you can do it:-

  • install terminal notifier with brew install terminal-notifier
  • install erc-terminal-notifier.el and add (require 'erc-terminal-notifier) in your .emacs

You might want to enable -reply option in erc-terminal-notifier.el so that you get alert style notifications.

  • Just installing erc-terminal-notifier and terminal-notifier doesn't do it for me (and adding require in the emacs file). Erc still seems to still attempt sending messages to dbus. Is there a step that is not documented or I missed? The documentation for erc-terminal-notifier just seems to talk about installation.
    – Ashesh
    Commented Aug 5, 2018 at 12:56

Actually emil's suggestion is good. A quick and dirty way is override erc-notifications-notify. Add the below code to your ~/.emacs. No need to install dbus & extra files.

(require 'erc-desktop-notifications)

(defun erc-notifications-notify (nick msg)
  "Notify that NICK send some MSG via AppleScript."
     (concat "display notification \"" (oz/escape-applescript msg)
             "\" with title \"" (oz/escape-applescript nick) "\"")))

(defun oz/escape-applescript (str)
  "Quote \\ and \"."
  (let ((len (length str)) (i 0) (q "") char)
    (while (< i len)
      (setq char (substring str i (1+ i))
            i (1+ i))
      (when (or (string= char "\\") (string= char "\""))
        (setq q (concat q "\\")))
      (setq q (concat q char)))

Notifications are shown as alerts or banners, depending on your settings in System Preferences > Notifications > Emacs.

  • Overriding such functions wholesale is pretty ugly. We have advice-add to do it in a more polite way. For oz/escape-applescript, I recommend you use replace-regexp-in-string.
    – Stefan
    Commented Jun 25, 2019 at 16:09
  • Why? The advice feature lets you add to the existing definition of a function, by advising the function. But we don't need the original code of erc-notifications-notify at all here. And personally I don't like regexp because it makes code unreadable. (replace-regexp-in-string "\\([\\\"]\\)" "\\\\\\1" str)) I am basically C/C++ programmer.
    – Yez Ezey
    Commented Jun 26, 2019 at 19:00
  • You can also completely override the function with add-advice, but with the advantage that it's properly recorded, so C-h f will tell you about it and you can de-override it later if you want.
    – Stefan
    Commented Jun 26, 2019 at 20:41
  • The main reason I suggested replace-regexp-in-string is because your loop has a classic O(N^2) behavior since it loops N times and each iteration uses concat which is itself O(N).
    – Stefan
    Commented Jun 26, 2019 at 20:43

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.