xmonad: Bind XF86Audio keys with EZConfig

This article was published 5 years ago. Due to the rapidly evolving world of technology, some concepts may no longer be applicable.

I used to just run gnome-settings-daemon to handle my media keys, but as of Ubuntu 14.10 it’s stopped working. I figured that it was about time that I managed them properly by binding keys in my Xmonad config.

myBindings =
    [ ("<XF86AudioMute>"  , spawn "amixer -q -D pulse sset Master toggle")
    , ("<XF86AudioRaiseVolume>"  , spawn "amixer -q -D pulse sset Master 2000+ unmute")
    , ("<XF86AudioLowerVolume>"  , spawn "amixer -q -D pulse sset Master 2000- unmute")
    , ("<XF86AudioPlay>"  , spawn "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause")

There are other bindings in there too, but these are the ones we’re interested in. We use amixer to set the volume on our audio device. It’s all fairly straightforward, but you might have to work out what your output device is called if you have multiple. For me, it was called Master (which is the default).

As a little bonus, I even managed to get the play/pause button to control Spotify via dbus. To achive this, we use dbus-send and send the PlayPause command

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause

Thoughts on this post

Joshua Hoffer 2014-11-28

On Archlinux, I’ve had the media keys bound to running pulseaudio-ctl [mute,down,up] Though pulseaudio-ctl is Archlinux specific, it’s just a bash script frontend for pacmd (pulseaudio). Anyway, it’s encouraging to see people using xmonad.

Leave a comment?