Windows play/pause keys on Xubuntu Spotify
Xfce/Xubuntu actually already includes the functionality to map multimedia keys to custom commands, so this can be done without having to install any extra packages or create any files:
-
Bind the keys
(This can also be done manually through Settings → Keyboard → Application Shortcuts)xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/XF86AudioPlay -s "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause" -n -t string xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/XF86AudioNext -s "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next" -n -t string xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/XF86AudioPrev -s "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous" -n -t string
Log out and log back in (alternatively you can close any apps that may be intercepting multimedia keys, in my instance this meant Google Chrome)
It worked for me on two different computers: A Dell Optiplex running Xubuntu 14.04 and a Thinkpad running Xubuntu 16.04.
I also added a few additional notes with more detailed troubleshooting, etc. here: https://gist.github.com/bmaupin/acc566ff44a8ebf20c2aa2707789e6ea
Install xbindkeys.
$ sudo apt-get install xbindkeys
Create the default configuration file for xbindkeys.
$ xbindkeys --defaults > ~/.xbindkeysrc
Edit the configuration file for xbindkeys.
$ nano ~/.xbindkeysrc
Add these lines:
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause"
XF86AudioPlay <-- or the key(s) you want
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop"
XF86AudioStop <-- or the key(s) you want
other examples of key binding:
# spotify controls
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause"
F8 <-- key assigned
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next"
F9 <-- key assigned
Run xbindkeys to see if it all works:
$ xbindkeys
Now, when Spotify is running, pressing the play/pause key will make your music start or stop.
You will need to set xbindkeys
to run automatically on startup.
On Ubuntu, System -> Preferences -> Startup Applications
.
Done!
sources: https://shkspr.mobi/blog/2011/12/linux-spotify-keybindings/ https://gist.github.com/jbonney/5743509#file-spotify_keybindings-L1