Playing with D-Bus interface of Spotify for Linux

After a lot of requests from Linux users, Spotify developers have integrated D-Bus support in version So, what this means is simply and awesome! Now Linux developers could use this programmatic interface to interact with Spotify from other apps.

In other words, now is quite simple to send «play», «pause», «move next/previous song» events to Spotify and with this get Spotify fully integrate into our desktop.

I will explain how to introspect D-Bus interface and make some proof-concepts.

Take care that Spotify Linux client now implements to MPRIS2 Dbus support and almost the entire available libraries of D-Bus could interact with it.

So now we play around to “play” with D-Bus API of Spotify. But first of all we have to install one simple package (I’m using Ubuntu Maverick Merkat, take care of your linux distribution and version to find differences).

Now let’s find what is the Spotify D-Bus’s initial interface.

$ mdbus2|grep spotify

So, as you could see there are two interfaces to talk with, but looks like the second one is our desired central point. Let’s introspect it…

$ mdbus2 org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2
[METHOD]    org.mpris.MediaPlayer2.Raise() -> ()
[METHOD]    org.mpris.MediaPlayer2.Quit() -> ()
[PROPERTY] b:CanQuit )
[PROPERTY] b:CanRaise )
[PROPERTY] b:HasTrackList )
[PROPERTY] s:Identity )
[PROPERTY] s:DesktopEntry )
[PROPERTY] as:SupportedUriSchemes )
[PROPERTY] as:SupportedMimeTypes )
[METHOD]    org.mpris.MediaPlayer2.Player.Next() -> ()
[METHOD]    org.mpris.MediaPlayer2.Player.Previous() -> ()
[METHOD]    org.mpris.MediaPlayer2.Player.Pause() -> ()
[METHOD]    org.mpris.MediaPlayer2.Player.PlayPause() -> ()
[METHOD]    org.mpris.MediaPlayer2.Player.Stop() -> ()
[METHOD]    org.mpris.MediaPlayer2.Player.Play() -> ()
[METHOD]    org.mpris.MediaPlayer2.Player.Seek( x:Offset ) -> ()
[METHOD]    org.mpris.MediaPlayer2.Player.SetPosition( o:TrackId, x:Position ) -> ()
[METHOD]    org.mpris.MediaPlayer2.Player.OpenUri( s:none ) -> ()
[SIGNAL]    org.mpris.MediaPlayer2.Player.Seeked( x:Position )
[PROPERTY] s:PlaybackStatus )
[PROPERTY]  org.mpris.MediaPlayer2.Player.readwrite( s:LoopStatus )
[PROPERTY]  org.mpris.MediaPlayer2.Player.readwrite( d:Rate )
[PROPERTY]  org.mpris.MediaPlayer2.Player.readwrite( b:Shuffle )
[PROPERTY] a{sv}:Metadata )
[PROPERTY]  org.mpris.MediaPlayer2.Player.readwrite( d:Volume )
[PROPERTY] x:Position )
[PROPERTY] d:MinimumRate )
[PROPERTY] d:MaximumRate )
[PROPERTY] b:CanGoNext )
[PROPERTY] b:CanGoPrevious )
[PROPERTY] b:CanPlay )
[PROPERTY] b:CanPause )
[PROPERTY] b:CanSeek )
[PROPERTY] b:CanControl )
[METHOD]    org.freedesktop.DBus.Properties.Get( s:interface_name, s:property_name ) -> ( v:value )
[METHOD]    org.freedesktop.DBus.Properties.Set( s:interface_name, s:property_name, v:value ) -> ()
[METHOD]    org.freedesktop.DBus.Properties.GetAll( s:interface_name ) -> ( a{sv}:values )
[METHOD]    org.freedesktop.DBus.Introspectable.Introspect() -> ( s:xml_data )

Interesting, isn’t it? It have a large D-Bus API to send events to Spotify. Among methods to control the playlist, one of my favourites is get MetaData from the playing song.
So now if you want to pause your actual song of Spotify you can issue at your terminal:

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause

The next steps for Ubuntu users is use this API to integrate indicator-sound and get fully integrated Spotify in our system.
I’m looking forward Spotify developers to integrate LibNotify and show track information with desktop notifications.

Happy hacking!


For playing songs from a spotify url just issue the next command:

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri string:spotify:track:6JfGHYsw9LVH5FJMCh66Um

John Reese has created a gorgeous wrapper for integrating Spotify with media keys by taking the above explanations. Check it out


Exists a better way to connect Spotify with GNOME-shell, recently it was published a new extension for integrate Spotify with GNOME.

And according to the Spotify community forum in the coming months it could be a native integration. The Spotify for Linux client changelog says the next line:  “Linux only: Media key support in Gnome. Coming soon!”

  • Nick

    Great! I now finally was able to add nice shortcuts using the Compiz Config Settings Manager and add thing like:
    dbus-send –print-reply –dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next
    dbus-send –print-reply –dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous

  • Mattias

    I’ve gotten play/pause through mediabuttons, ssh and webserver working and i LOVE it! One thing however I have not figured out, and that is how to use org.mpris.MediaPlayer2.Player.OpenUri, my guess is that it should allow me to start a specific song/playlist. If you figure it out I’d be delighted to read about it. ;)

  • Fran Diéguez

    Hi Mattias,

    This is quite simple!! Just issue in your terminal the next command:

    dbus-send –print-reply –dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri string:spotify:track:6JfGHYsw9LVH5FJMCh66Um

    Look at the right way of passing parameters with dbus.

  • Pingback: Let's see where this leads...()

  • Richard Reijmers

    Flippin’ great, finally a good how-to about dbus. The original dbus documentation lacks a proper example on how to implement this in real life, great work!

  • Richard Reijmers

    I combined the commands with AutoKey to make keyboard shortcuts to skip, play, pause etc.

    system.exec_command(“dbus-send –print-reply –dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Play”, getOutput=False)

  • Fran Diéguez

    @richard thanks for your read!

  • Jonathan Trengrove

    This is just what I’ve been looking for! :)
    Really good to have global keyboard shortcuts for native Spotify now.

    Gotta love the Linux community :)

  • Pingback: Terence Eden has a Blog » Linux Spotify Keybindings()

  • OJ

    This is great. I’m no D-Bus expert, and I have a question.

    How do I check if shuffle is on, and how do I toggle it when:

    [PROPERTY] org.mpris.MediaPlayer2.Player.readwrite( b:Shuffle )


  • oj88

    Spotify + D-Bus is great.

    I have used it to write this web-based remote control for Spotify for Linux:

    Screenshots and video available.

    Works great!

  • Ruhan

    Incredible feature. I put it in my custom shortcuts to next/previous and pause musics.

  • Daniel W

    haha great song choice dude!
    Shortcut >> commence *le sexytime :P

  • Thor

    I was wondering if it is possible to start a specific playlist from the terminal? I am working on a alarm_clock in python and would like to wake up to a specific spotify playlist.

  • Sinan Alzaeem

    I search for this issue also