Skip to content

Instantly share code, notes, and snippets.

@jbonney
Created June 9, 2013 13:22
Show Gist options
  • Save jbonney/5743509 to your computer and use it in GitHub Desktop.
Save jbonney/5743509 to your computer and use it in GitHub Desktop.
Spotify - Linux key bindings. From XFCE / Ubuntu keyboard shortcuts configuration, assign the control command to their key. http://shkspr.mobi/blog/2011/12/linux-spotify-keybindings/
"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" XF86AudioPrevious
@chfritz
Copy link

chfritz commented Nov 18, 2018

For anyone curious which other commands the spotify client supports try:

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Introspectable.Introspect

This lists another method "Seek". Unfortunately it doesn't seem to do anything though, because no matter what value I try for Offset, it doesn't have any effect:

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Seek int64:10

Still wanted to leave it here in case anyone else wants to figure this out. Seemed useful.

@arthurmbandeira
Copy link

Is there a command for the "15 seconds" key in Spotify?

@AugustoCalaca
Copy link

AugustoCalaca commented Jul 13, 2019

It's work on Debian 10

@andrefsp
Copy link

andrefsp commented Aug 5, 2019

Debian 10 - Buster.

Works just fine.

@chfritz
Copy link

chfritz commented Oct 1, 2019

For anyone else with this issue: In Ubuntu 18.04 using the snap version of Spotify the media keys work out of the box, except that Chrome is a little greedy and captures these keys (presumably to control YouTube content and the like). The good news is that this can be disabled here:
chrome://flags/#hardware-media-key-handling. After doing so the media key events will pass-through to Spotify again.

@mroliveira7
Copy link

mroliveira7 commented Nov 4, 2019

Working great xubuntu 18.04
Thanks a lot!

@kobymeir
Copy link

@chfritz 10x so much that helped a lot

@chfritz
Copy link

chfritz commented Jan 22, 2020

And for anyone interested in querying the currently running song, this can be gotten from:

dbus-send --dest=org.mpris.MediaPlayer2.spotify --print-reply /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata

Sample output:

method return time=1579663676.086557 sender=:1.134 -> destination=:1.420 serial=406 reply_serial=2
   variant       array [
         dict entry(
            string "mpris:trackid"
            variant                string "spotify:track:3d8Awbi4CFYp4Wp231MqdS"
         )
         dict entry(
            string "mpris:length"
            variant                uint64 433000000
         )
         dict entry(
            string "mpris:artUrl"
            variant                string "https://open.spotify.com/image/ab67616d00001e02bd3afe3a0169e70901d2933e"
         )
         dict entry(
            string "xesam:album"
            variant                string "Total 7"
         )
         dict entry(
            string "xesam:albumArtist"
            variant                array [
                  string "Various Artists"
               ]
         )
         dict entry(
            string "xesam:artist"
            variant                array [
                  string "Oxia"
               ]
         )
         dict entry(
            string "xesam:autoRating"
            variant                double 0.01
         )
         dict entry(
            string "xesam:discNumber"
            variant                int32 2
         )
         dict entry(
            string "xesam:title"
            variant                string "Domino"
         )
         dict entry(
            string "xesam:trackNumber"
            variant                int32 11
         )
         dict entry(
            string "xesam:url"
            variant                string "https://open.spotify.com/track/3d8Awbi4CFYp4Wp231MqdS"
         )
      ]

@sago104
Copy link

sago104 commented Aug 9, 2020

Thanks for the help! I follow your instructions. Now I can command Spotify in Manjaro KDE just with a little change.

I add this photo for guide in global hotkeys

image

@ilya-bystrov
Copy link

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Seek int64:10

Find out that seek value is specified in microseconds. So you have specify int64:1000000 for 1 sec. It works for me.

@brccabral
Copy link

This works with Spotify, but then YouTube stops working (running from Brave browser). Is there a way to keep both Spotify and YouTube?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment