D-Bus and Emacs

I have, from time to time, written Emacs posts that are specific to macOS. Lots of folks use macOS so I don’t apologize for that but lots of folks use some flavor of Linux too so it’s only fair to recognize some Linux specific Emacs uses as well.

Lars Ingebrigtsen is a Linux/Emacs user who likes things the way he likes them and who has no patience for systems that don’t meet his needs exactly. He has an interesting post that lists three such problems:

  1. His laptop goes into power save mode sooner than he’d like.
  2. When he closes his laptop cover it goes to sleep like most laptops. He doesn’t like that for reasons you can read in his post. He wants it to turn off his screen and nothing else.
  3. When he turns off his Bluetooth speakers, he wants his laptop to stop playing music.

He noticed that what all these problems have in common is that he wants to react to some hardware event in his own way, not in the way the system developers thought best. His solution to this is to use D-Bus to listen for the requisite events and notify him when they occur. From there, it’s a simple matter to react in the appropriate way.

What may be surprising is that all this is written in Elisp. He doesn’t show the code in the post but does provide a link to it. The code is straightforward and there’s not much of it. It is, as he says, specific to his needs but should be easy to adopt to any user’s needs.

Sadly, this is mostly useful for Linux users although there is a port of D-Bus for macOS. I’ve never used it so I don’t know how well it would work for an application like this but it’s easy to install with Homebrew and worth checking out if you have problems similar to Ingebrigtsen’s.

This entry was posted in General and tagged . Bookmark the permalink.