Linux Spotify Media Keys for Ubuntu, ArchLinux and more!
Spotify is an amazing music service with awesome Linux support … except they never included proper media key support.
Here's how to make Spotify Linux respond to both Gnome Media Keys and custom media key settings from anywhere!
The first option, if you use Gnome or have integration with Gnome media key support is the easiest and best way to go about things.
John Reese created a very handy script to wrap around Spotify and give us global Gnome media key integration. You can grab it here:
The installation is rather simple, though I thought it was a little teebit confusing (though they are very straight forward and simple). I've provided two options for you:
- Follow the step by step process yourself (command line work required).
- Use my script to download and install it for you.
The step by step process:
- Visit the github page and download the code (https://github.com/jreese/spotify-gnome) … You can do this by clicking on the “ZIP” button near the top left.
- Extract the zip file.
- Open up a terminal and navigate to the extracted code.
- Find out where Spotify is installed:
- Use the command >”whereis spotify”.
- With luck, it'll say “/usr/bin/spotify”.
- If not, then refer to John's instructions to editing his code or ask me for help here in the comments.
- As root, copy the file from inside the extracted folder ‘bin' into the folder ‘/usr/local/bin/'.
- You can do this with: >”sudo cp bin/spotify /usr/local/bin/”.\
- Remeber to put the tailing ‘/' at the end!
- OR use John's version with: >”sudo install bin/spotify /usr/local/bin/”.
- Both will accomplish the task just fine. Pick one, not both!
- Exist spotify if you have it open. Then open it like you normally do by clicking on the spotify icon or via the commandline command >”spotify”.
It'll automatically wrap around Spotify and let you use media keys!
Using my script to download and install the Spotify Media Key Wrapper:
- Download my script: From Dropbox (https://dl.dropbox.com/u/3371442/install_spotify_media_keys.sh.tar.gz) or from github (https://github.com/PiotrKrzyzek/Bash-Scripts/tree/master/install_spotify_media_key_wrapper)
- Extract it.
- Run it with the command:
- > ./install_spotify_media_keys
My script will download and install everything for you and then clean-up after itself. 🙂
Using the non-media-key script way:
There is another way to use media keys with Spotify. It's by using Dbus commands pretty much directly.
What you're going to have to do it set your media keys to specific DBUS commands that do very specific Spotify commands. This works because Spotify has support for it, they just didn't implement it. You can use these in your .xbindkeysrc file or just set them through your system keyboard shortcuts applet. Either way works. Or even map them to a command-line alias or app; your choice. There is no wrong answer here.
Here is the code in a nutshell (originally from jylam):
1234 "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
Now let me explain the code:
dbus-send is the command to use dbus. –dest= is the application API you are using while /org/mpris is pretty much the protocol stuff and the thing like “org.mpris.MediaPlayer2.Player.PlayPause” is that actual command you are sending. “PlayPause” is well … the play and pause button in one. The rest is pretty obvious.
If you're mapping that to just a command, leave out the XF86AudioPlay part. That's for the .xbindkeysrc file stuff.
If you really want a customized and advanced experience: try this link: http://www.mabishu.com/blog/2010/11/15/playing-with-d-bus-interface-of-spotify-for-linux/
It details every possible command for Spotify via DBUS and the command line. It even tells you how you can play specific songs and music from a url! Cool stuff there.
If this has worked for you, let me know. If you have another solution, give a shout and let the world know!