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!


Share this post on…

  • Mastodon
  • Facebook
  • LinkedIn
  • BlueSky
  • Threads
  • Reddit
  • HackerNews
  • Lobsters
  • WhatsApp
  • Telegram

17 thoughts on “Linux Spotify Keybindings”

  1. 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 😉

    Reply
    1. 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

      Reply
        1. 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.

          Reply
  2. 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.

    Reply
    1. says:

      And, awesomely, this site's comment system has converted my double hyphens into emdashes. Rest assured that they should be double hyphens.

      Reply
      1. says:

        I've manually converted them to – Thanks for pointing out that I had included my home directory, rather than a generic one. Updated.

        Reply
  3. 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.

    Reply
  4. 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

    Reply
  5. sawhikes says:

    Can I make this binds multiplayered? For example this works on spotify xfce but don`t work with audacious.

    Reply

What are your reckons?

All comments are moderated and may not be published immediately. Your email address will not be published.

Allowed HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <p> <pre> <br> <img src="" alt="" title="" srcset="">