Intro
I recently noticed the Spotify linux port for CentOS, available from Negativo17.org, doesn't acknowledge pressing space to toggle pause and play.
Looking into keybindings felt overly complicated, so some searching later I found a post in the Spotify Desktop Linux forum.
What it basically amounts to, is sending dbus-commands to the Spotify player.
Since these are regular CLI-commands, they could be assigned to custom Panel buttons, and hey presto, we have easily accessible Spotify player controls!
Guide
Let's dig into it!
Command reference
For starters, these are the available commands.
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
Fire up the Spotify cllient, and try them out as-is on a command line!
There is no need to have the Spotify window focused.
Works nicely doesn't it!
Adding button controls
I use the Mate desktop environment (DE) on my personal CentOS 7-desktop , but the Panel works in a similar fashion for most DE's.
Let's start with a Play-pause toggle button.
- Right-click a free space on the panel where you want the buttons to be placed and click Add to panel.
- Mark Custom Application Launcher and click Add at the bottom.
- A Create Launcher-window pops up.
- Enter a (preferrably) descriptive name in the Name-field.
- Copy the entire Play-pause command line from above and paste it into the Command-field.
- Change the icon as needed. I chose the icons from /usr/share/icons/mate/256x256/actions, specifically these;
Play-pause: gtk-cancel.png (couldn't find a suitable play-pause button so this had to do).
Previous: go-first.png
Next: go-last.png - Click OK to save.
- Your new shortcut should now be visible on the panel.
- Repeat the steps for Previous and Next as needed.
- You are now done. Try out the new buttons. The Spotify window still doesn't need to be focused for the buttons to work.
Conclusion
Not to difficult as workarounds go IMHO.
- Adding shortcuts to the panel buttons should work if you have the correct desktop environment.
- For Mate, I haven't found any particular way to assign keyboard shortcuts yet, unfortunately.
Sources
https://negativo17.org/spotify-client/
https://community.spotify.com/t5/Desktop-Linux/Basic-controls-via-command-line/m-p/4360856#M15590