Force Media Keys to call Spotify on Linux Elementary OS or Ubuntu
Sometimes, it happens to me that my media keys are bound to Youtube or even don’t work at all. It’s really annoying when it happens because I only use them for Spotify. Let me show you how I fixed it to always be connected to Spotify.

Before going further, I invite you to test the following command in your terminal while having Spotify open to ensure the commands will work.
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
If your music stops, then we can begin :)
The commands needed for each binding are:
Play/Pause
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
Next
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next
Previous
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous
First, install xbindkeys-config in your terminal and then launch it.
sudo apt install xbindkeys-config
xbindkeys-config
In the interface, we will create three bindings for Play/Pause, Next and Previous.
- Enter a “Name” (ex: spotify-play)
- Click on “Get Key” and press the corresponding key
If it does not work, then go to your Settings >Keyboard > Shortcurts and in the Media section, assign the Action to the key - Enter the action as defined above
- Press apply
We repeat the steps for the other bindings and press “Save & Apply & Exit”.
Start your music and watch the magic take place.