13

I am trying to be able to play, pause, chose next track or previous track from command line, but unfortunately no one seems to know how to do this (I have goggled repeatedly). I need it to be a command so that I can use it with blue proximity, so pause when I walk away. Are there any commands for this?

Braiam
  • 69,112
Tim
  • 33,500

4 Answers4

18

The Spotify client has supported the MPRIS2 DBUS specification for ~4 years. Simply put this means most media remote controls should be able to control it.

If you need command-line access, you can talk to it directly over DBUS. Here's an example I stole from Fran DiƩguez:

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

For more commands, see the MPRIS2 Player specifications.

Oli
  • 299,380
9

The following command works for me (Play or Pause):

qdbus org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
guymac
  • 191
2

DBus commands for controlling spotify (from here), working for me on 17.10:

Play

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

Pause

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

Play/Pause toggle

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

Previous

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

Next

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

I have bound play/pause toggle to F12 in gnome.

Tim
  • 33,500
htaccess
  • 1,528
2

SP is a simple and effective command line tool to control spotify. It uses DBUS internally.

To install:

curl https://gist.githubusercontent.com/wandernauta/6800547/raw/db881a9100eb9b1e684c99962bde086a47ebcf08/sp | sudo tee /usr/local/bin/sp
sudo chmod +x /usr/local/bin/sp
cmc
  • 182