Ubuntu: Enabling Media Keys for Spotify

Updated Feb 2019 based on Spotify updates that broke this functionality.

If the keyboard media keys do not work from your Ubuntu desktop, you can use D-Bus support to send the proper commands to Spotify.  Validate the following commands from the console:

Play/Pause

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

Next

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

Previous

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

Enable Media Key Shortcut

To tie these to the keyboard, go to Settings > Keyboard > Application Shortcuts; Custom Shortcuts, then “+” to add.

Use one of the commands above to fill in the dialog, and press “Apply”.

Then click on the right column and it will toggle between “disabled” and “new accelerator…”.  When it says “new accelerator”, press the media key that you want to tie to this command.

The next and previous media keys always work when bound this way, but I’ve had trouble with the play/pause media key.  You may have to bind the command to the media launch button or a function key (F1..F12) instead.

 

References:

Community page showing commands that work for latest Spotify

http://laivakoira.typepad.com/blog/2012/01/how-to-toggle-playingpausing-of-spotify-using-the-pause-key-in-ubuntu.html

https://gist.github.com/arthurlutz/3636183