0

Running sleep 1s && tput bel inside iTerm and quickly tabbing out into another application displays this very nice notification badge in the Dock:

mac dock badge on ringing a bell

I tried running (shell-command "sleep 1s && tput bel") or calling something like echo -e "\a", but there is no audible beep or that nice Dock badge. It just displays ^G.

I am interested in using this badge for new emails, linking it into mu4e-alert as a subtle way to notify me because I don't want to use the full-size notifications provided by something like terminal-notifier -message "New email...".

Does anyone know of other ways how I could get this badge to appear? I especially like the integration into macOS that the badge goes away on its own when the application is launched into its foreground.


I also tried the built-in (beep) and it beeps, but does not display the Dock badge when Emacs is not in focus:

(sleep-for 2)
(beep)
Dima
  • 101
  • 2
  • This feature is named badge label and can be set in Swift via `NSApplication.shared.dockTile.badgeLabel = "1"`. – Dima Nov 25 '20 at 08:04

1 Answers1

2

It's certainly possible, but you should understand that this has nothing to do with BEL characters or beeps. Any OSX application can call the system API that adds the badge to the dock icon any time it wants. Your email program does it when you receive an email, and iTerm does it when it sees a BEL character. But you're not running Emacs inside of iTerm, so the BEL character has no special effect. What you need to do is consult the developer documentation for OSX, find out what APIs have to be called, extend Emacs to include Lisp functions that call those APIs, and finally write Lisp that triggers Emacs to make those calls in appropriate situations.

It's actually possible that some of this work has already been done, but as a rule Emacs tends not to support many platform-unique features. Features that exist across platforms but are simply implemented in a different way are commonly supported by Emacs, but not features that exist only on one platform. This is particularly true of features that exist only on OSX, as OSX is non-Free. Don't let that stop you from extending Emacs to better suit you though.

NickD
  • 27,023
  • 3
  • 23
  • 42
db48x
  • 15,741
  • 1
  • 19
  • 23