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!


14 Responses to “Linux Spotify Keybindings”

  1. Elfar Image of Elfar

    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 ;)

    Reply
    • Elmervc Image of Elmervc

      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](http://pastebin.com/i1YfDLY6)

      Reply
        • Elmervc Image of Elmervc

          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.

          Reply
  2. offlein Image of offlein

    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.

    Reply
  3. Søren Image of Søren

    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.

    Reply

What Do You Reckon?