Linux Spotify Keybindings
Hurrah! Spotify have released a native Linux player which works with free accounts!
These notes show (which are mostly for my benefit) show you how to install it and configure your multimedia keyboard so the play/pause key controls the music on Spotify.
Download Spotify for Linux. It's available in 32bit or 64bit.
Double click on the .deb that has been downloaded and it should install. Nice and easy!
To get the multimedia keys working, we need to follow the instructions in this tutorial and the codes described at lnxscene.
Install xbindkeys.
sudo apt-get install xbindkeys
Create the default configuration file for xbindkeys.
xbindkeys --defaults > ~/.xbindkeysrc
Edit the configuration file for xbindkeys.
nano ~/.xbindkeysrc
Add these lines:
"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
Run xbindkeys to see if it all works
xbindkeys
Now, when Spotify is running, pressing th eplay/pause key will make your music start or stop.
You will need to set xbindkeys to run automagically on startup.
On Ubuntu, System -> Preferences -> Startup Applications.
Done!
Elfar says:
Thanks a lot for the commands. I did not install xbindkeys and just opened the the normal keyboard app and added shortcuts there, avoids installing xbindkeys and setting something to run at start (which is fine if one prefers that). Also added Next and Previous shortcuts as these were easy to guess 😉
Elmervc says:
I tried this also, but for some reason I need to have the focus on Spotify's window in order to work. Strange enough the Previous button doés work without having focus on Spotify. I've added 4 custom commands using the keyboard settings, reassigning the already existing bindings for those media keys.
When I use xbindkeys, I don't have this issue 😕
ps. Here are the config lines for xbindkeys, including next/prev pastebin.com/i1YfDLY6
Søren says:
It looks like you are missing two whitespaces before your shortcut. Mine looks like this (shortcut: ctrl+alt+shit+p): http://pastebin.com/tMAJddGG
Elmervc says:
According to the formatting mentioned in the config file as provided with xbindkeys you are right. The config I pastebin'ed works, so I think white spaces are ignored and these are inserted purely for cosmetic reasons. The problem I mentioned is only when I use Ubuntu's built-in keyboard settings.
offlein says:
For what it's worth, this post contains an error in the line "xbindkeys --defaults > /home/edent/.xbindkeysrc" ... It would be better if the line was: "xbindkeys ––defaults > ~/.xbindkeysrc"
Also -- using the defaults per that line did some annoying stuff. Ctrl-shift-q will then bring up a window listing your xbindkeys configurations -- which is fine i guess, except more odiously, Ctrl-F (normally used for "find"ing things on a page) will be overwritten with a useless shortcut to xterm.
Simply comment those lines out of your ~/.xbindkeysrc file if you don't want those things, kill your current xbindkeys process and re-open it.
offlein says:
And, awesomely, this site's comment system has converted my double hyphens into emdashes. Rest assured that they should be double hyphens.
Terence Eden says:
I've manually converted them to – Thanks for pointing out that I had included my home directory, rather than a generic one. Updated.
jokuvaa says:
I need commands for next and previous also! 🙂
Søren says:
Tanks! If you don't have a dedicated play/pause button on you keyboard you can run
xbindkey -k
which will record a key combination and output the textual representation which be put into your .bindkeysrc file.Chris says:
Did it stop working? i get "no such file or directory" error.
Terence Eden says:
Which version of Linux and Spotify are you using?
Chris says:
Xubuntu 13.04, Spotify 0.9.1.55
jan says:
Thanks for posting this, exactly what I needed.
Rafał says:
Thanks, worked like a charm!
liquid2026 says:
For me this works perfectly:
"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.Next" XF86AudioNext "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous" XF86AudioPrev
Jeison says:
I worked perfectly on ubuntu + xfce4. Thanks a lot!
sawhikes says:
Can I make this binds multiplayered? For example this works on spotify xfce but don`t work with audacious.