allenap

1 note

Script to control native Spotify on Linux

Almost the simplest possible Python script to control the native Spotify client on Linux:

#!/usr/bin/env python

import dbus
import sys

if __name__ == '__main__':
    session = dbus.SessionBus.get_session()
    spotify = session.get_object(
        "org.mpris.MediaPlayer2.spotify",
        "/org/mpris/MediaPlayer2")
    for command in sys.argv[1:]:
        getattr(spotify, command)()

Use like:

$ spotify-control PlayPause
$ spotify-control Next
$ spotify-control Previous

I was helped by reading Playing with D-Bus interface of Spotify for Linux.

Filed under python spotify dbus

  1. allenap posted this