Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Spotify - Linux key bindings. From XFCE / Ubuntu keyboard shortcuts configuration, assign the control command to their key. http://shkspr.mobi/blog/2011/12/linux-spotify-keybindings/
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause" XF86AudioPlay
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop" XF86AudioStop
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next" XF86AudioNext
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous" XF86AudioPrevious
@sjug

This comment has been minimized.

Copy link

sjug commented Mar 28, 2015

This is still working great, just a suggestionf for users on XFCE...
Just add the quotation part to the Keyboard > Application Shortcuts, then associate it with any key you'd like. (if you don't have media keys on your keyboard)

@katef

This comment has been minimized.

Copy link

katef commented Aug 20, 2015

Thanks for this!

@melki

This comment has been minimized.

Copy link

melki commented Feb 28, 2016

Awesome ! Thank you

@narcelio

This comment has been minimized.

Copy link

narcelio commented Apr 11, 2016

Thanks!

@liquid2026

This comment has been minimized.

Copy link

liquid2026 commented Apr 12, 2016

Note it's not XF86AudioPrevious it's XF86AudioPrev and you must have the command on the second line.

"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause"
XF86AudioPlay
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop"
XF86AudioStop
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next"
XF86AudioNext
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous"
XF86AudioPrev

@ZERO20

This comment has been minimized.

Copy link

ZERO20 commented May 24, 2016

Thank you! I worked for me !

@Wesdesignz

This comment has been minimized.

Copy link

Wesdesignz commented Jun 7, 2016

I'm on Ubuntu 16.04: for me it was required to install these package(s):
sudo apt-get install mpdris2 mpris-remote
(I haven't tested which of the 2 actually worked)

Then, I tested the following: I've dropped the quotes and removed the last part after the last quote, as this part didn't work for me (got an error: Data item "XF86AudioPlay" is badly formed).

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

@henningsway

This comment has been minimized.

Copy link

henningsway commented Jun 10, 2016

any way to program a "save to your music" shortcut? For pause/skip/etc ubuntu-shortcuts from keyboard preferences seem to work finde.

@duke90

This comment has been minimized.

Copy link

duke90 commented Jul 4, 2016

Hail to the king, baby! :) Thanks man. Just switched to xubunbu, and it made me a headache to use my so-loved keyboard hotkey and mouse gesture to pause the music!

@lusentis

This comment has been minimized.

Copy link

lusentis commented Jul 11, 2016

Thanks! 👍

@derWeihnachtsmann

This comment has been minimized.

Copy link

derWeihnachtsmann commented Jul 17, 2016

Thank you very much for this bro!

@xtonousou

This comment has been minimized.

Copy link

xtonousou commented Aug 15, 2016

Thanks m8!

@otroboe

This comment has been minimized.

Copy link

otroboe commented Aug 19, 2016

Awesome thank you !

@johnnymatthews

This comment has been minimized.

Copy link

johnnymatthews commented Sep 12, 2016

Exactly what I needed thanks! Now when I press F8 the music play/pauses, and when I press F9 Spotify skips to the next track.


For those who are struggling, here's what I did:

In terminal

sudo apt-get install xbindkeys
cd ~/
sudo vim .xbindkeysrc

Scrolled to the bottom of the file and pasted

# spotify controls
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause"
  F8

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

Then saved and exited.

I used VIM but you can probably just as easily use another text editor like Nano or something.

@b-m-f

This comment has been minimized.

Copy link

b-m-f commented Sep 30, 2016

Great! Thanks

@Fkawala

This comment has been minimized.

Copy link

Fkawala commented Oct 10, 2016

It rocks ! Thank you

@kitzberger

This comment has been minimized.

Copy link

kitzberger commented Nov 15, 2016

Thanks for this snippet!

Had to rename XF86AudioPrevious to XF86AudioPrev though for me to work on Ubuntu 16.04

@SoyGoodPeople

This comment has been minimized.

Copy link

SoyGoodPeople commented Dec 9, 2016

Linux XFCE Manjaro Work perfect

@Tacabuco

This comment has been minimized.

Copy link

Tacabuco commented Dec 17, 2016

Thank you very much, you helped me a lot ;D

@barnaba

This comment has been minimized.

Copy link

barnaba commented Feb 10, 2017

For all two i3 guys:

bindsym $mod+Left exec dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous
bindsym $mod+Down exec dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop    
bindsym $mod+Up exec dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause 
bindsym $mod+Right exec dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next   
@khallaghi

This comment has been minimized.

Copy link

khallaghi commented Mar 5, 2017

I still have problem with previous and next keys on Ubuntu 14.04 & XFCE4 even though after changing XF86AudioPrevious to XF86AudioPrev but play and pause keys are perfect.

@alijawadfahs

This comment has been minimized.

Copy link

alijawadfahs commented Mar 8, 2017

Wesdesignz thanks
worked perfectly !

@lamroger

This comment has been minimized.

Copy link

lamroger commented Mar 9, 2017

thanks @mohnjatthews ! also have to remember run xbindkeys

@joaquinsimenthal

This comment has been minimized.

Copy link

joaquinsimenthal commented Mar 14, 2017

What can I do to config my keys in Openbox on Antergos or Archlinux?

Thank you so much for your help in advance...

@MohammedEihab01

This comment has been minimized.

Copy link

MohammedEihab01 commented Mar 28, 2017

well that worked ,,but it stopped the hotkeys for Rhythmbox the default player on XFCE4
any help to get the shortcuts to work for both ?

@frontman

This comment has been minimized.

Copy link

frontman commented Apr 23, 2017

Works on 4.8.17 Gallium OS. Thank you!

@sistemaon

This comment has been minimized.

Copy link

sistemaon commented Apr 23, 2017

THANKS!
Works on Manjaro OS Edition (17.0.1) XFCE (4.12)

@axd

This comment has been minimized.

Copy link

axd commented May 4, 2017

Thanks @liquid2026

That's actually worked for me after a lot of failures. - https://gist.github.com/jbonney/5743509#gistcomment-1749006

OS: Xubuntu 16.04

@dragonalvaro

This comment has been minimized.

Copy link

dragonalvaro commented May 25, 2017

I still have problem with previous and next keys on Ubuntu 14.04 & XFCE4 even though after changing XF86AudioPrevious to XF86AudioPrev but play and pause keys are perfect.

I'm having the same issue on Xubuntu 17.04

@gianllucah

This comment has been minimized.

Copy link

gianllucah commented May 29, 2017

God bless you

@SilverTuxedo

This comment has been minimized.

Copy link

SilverTuxedo commented Jun 27, 2017

Thank you so very much! I Wish I had seen this sooner.

@PetterJ123

This comment has been minimized.

Copy link

PetterJ123 commented Oct 8, 2017

Bless every little part of you, have been searching for this solution in forever! Can't thank you enough! <3

@luperr

This comment has been minimized.

Copy link

luperr commented Oct 19, 2017

Thank you very much!

@Endur3

This comment has been minimized.

Copy link

Endur3 commented Oct 19, 2017

Awesome, thanks!

@SergioGeeK7

This comment has been minimized.

Copy link

SergioGeeK7 commented Oct 25, 2017

great job

@graves501

This comment has been minimized.

Copy link

graves501 commented Oct 27, 2017

@liquid2026 worked like a charm, thx!

@Nukencio

This comment has been minimized.

Copy link

Nukencio commented Nov 14, 2017

Thanks guys! :D
Working in Xubuntu 16.04.3

@bbrrck

This comment has been minimized.

Copy link

bbrrck commented Nov 27, 2017

thanks!

@dsalinux

This comment has been minimized.

Copy link

dsalinux commented Dec 4, 2017

Perfect, thanks!

@rust20

This comment has been minimized.

Copy link

rust20 commented Jan 17, 2018

Thanks!

@varh1i

This comment has been minimized.

Copy link

varh1i commented Jan 21, 2018

Thanks @sjug !

@campanoon

This comment has been minimized.

Copy link

campanoon commented Feb 4, 2018

Thanks @jbonney for the command and @sjug for the suggestion!

@andredxc

This comment has been minimized.

Copy link

andredxc commented Feb 6, 2018

Still works, thanks!!

@felixhummel

This comment has been minimized.

Copy link

felixhummel commented Mar 14, 2018

Thank you very much! :)

@lsl

This comment has been minimized.

Copy link

lsl commented Apr 17, 2018

Bindsym version for the i3wm people using media keys (.i3/config)

# Bind media keys to spotify play, stop, next, previous
bindsym XF86AudioPlay exec dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
bindsym XF86AudioStop exec dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop
bindsym XF86AudioNext exec dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next
bindsym XF86AudioPrev exec dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous
@ptaferner

This comment has been minimized.

Copy link

ptaferner commented Apr 19, 2018

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

Those work absolutely fine for me on Ubuntu 17.10 when defined as "Custom Shortcuts" via Gnome Settings.

@Dessix

This comment has been minimized.

Copy link

Dessix commented May 27, 2018

To improve upon @barnaba's example for I3 users, and for those preferring direct media keys on hardware without fiddling with the Gnome controls UI:

# Pulse Audio controls
bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ +5% #increase sound volume
bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ -5% #decrease sound volume
bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute @DEFAULT_SINK@ toggle # mute sound

# Media keys

## Using [playerctl](https://github.com/acrisci/playerctl)
bindsym XF86AudioPrev exec --no-startup-id playerctl previous
bindsym XF86AudioNext exec --no-startup-id playerctl next
bindsym XF86AudioPlay exec --no-startup-id playerctl play-pause
bindsym XF86AudioPause exec --no-startup-id playerctl pause
bindsym XF86AudioStop exec --no-startup-id playerctl stop

## Non-playerctl option for Ubuntu
# bindsym XF86AudioPrev exec --no-startup-id "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous"
# bindsym XF86AudioNext exec --no-startup-id "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next"
# bindsym XF86AudioPlay exec --no-startup-id "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause"
# bindsym XF86AudioPause exec --no-startup-id "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause"
# bindsym XF86AudioStop exec --no-startup-id "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop"

@h3ct0r

This comment has been minimized.

Copy link

h3ct0r commented Jun 29, 2018

Thanks! Worked very well on a DELL 5777 laptop with a vanilla Xubuntu 16.04!

@GarciaSouza

This comment has been minimized.

Copy link

GarciaSouza commented Jul 4, 2018

T.K.S!!!
Worked very well on a Lenovo IdeaPad 320 laptop with a Xubuntu 17.10 artful!

@torgeir

This comment has been minimized.

Copy link

torgeir commented Sep 8, 2018

To date https://gist.github.com/jbonney/5743509#gistcomment-1422561 is still working perfectly on xfce/ubuntu studio 👏

@chfritz

This comment has been minimized.

Copy link

chfritz commented Nov 18, 2018

For anyone curious which other commands the spotify client supports try:

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Introspectable.Introspect

This lists another method "Seek". Unfortunately it doesn't seem to do anything though, because no matter what value I try for Offset, it doesn't have any effect:

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Seek int64:10

Still wanted to leave it here in case anyone else wants to figure this out. Seemed useful.

@arthurmbandeira

This comment has been minimized.

Copy link

arthurmbandeira commented Jul 11, 2019

Is there a command for the "15 seconds" key in Spotify?

@AugustoCalaca

This comment has been minimized.

Copy link

AugustoCalaca commented Jul 13, 2019

It's work on Debian 10

@andrefsp

This comment has been minimized.

Copy link

andrefsp commented Aug 5, 2019

Debian 10 - Buster.

Works just fine.

@chfritz

This comment has been minimized.

Copy link

chfritz commented Oct 1, 2019

For anyone else with this issue: In Ubuntu 18.04 using the snap version of Spotify the media keys work out of the box, except that Chrome is a little greedy and captures these keys (presumably to control YouTube content and the like). The good news is that this can be disabled here:
chrome://flags/#hardware-media-key-handling. After doing so the media key events will pass-through to Spotify again.

@mroliveira7

This comment has been minimized.

Copy link

mroliveira7 commented Nov 4, 2019

Working great xubuntu 18.04
Thanks a lot!

@kobymeir

This comment has been minimized.

Copy link

kobymeir commented Dec 12, 2019

@chfritz 10x so much that helped a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.