Kothar Labs Contact Me

Spotify for Linux media keys with DBUS

Wed, 11 May 2011 / blog / spotify

Now that Spotify has discontinued the free account, and restricted me to an 'open' account with only 10 hours of music a month, I've ended up paying for an 'unlimited' account.

While I'm a little disappointed with this turn of events, it does mean I am now able to use the Linux client. It seems pretty decent so far, but I wanted to map some keys to do things like play/pause and next.


Luckily DBUS is supported, so you can create new key mappings in Gnome as desired. I found a fairly concise list of the most useful key bindings on jylam's page:

"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause" XF86AudioPlay
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop" XF86AudioStop
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous" XF86AudioPrev
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next" XF86AudioNext

For those who are interested, there's a more complete exploration of the available commands at Mabishu, and a tool which makes use of the API for track notifications at Muffin Research Labs.

UPDATE:

John Reese has implemented a program to automatically provide the mappings needed to control Spotify over DBUS. You can get it from GitHub.