Skip to content

Instantly share code, notes, and snippets.

@sh4dowb
Last active July 19, 2023 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sh4dowb/aa2471d5799b706a22850c522c366776 to your computer and use it in GitHub Desktop.
Save sh4dowb/aa2471d5799b706a22850c522c366776 to your computer and use it in GitHub Desktop.
linux spotify media keys are sometimes not working after another media is played, and spotify is restarted. this command fixes it
dbus-monitor | grep --line-buffered interface=org.mpris.MediaPlayer2.Player | grep --line-buffered -v spotify | awk -W interactive -F'member=' '{print $2}' | xargs -L1 -I {} dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.{}
# when you play another media, and restart spotify, media keys get sent to another destination.
# in my case, it was VLC. output from dbus-monitor:
#
# method call time=1586780292.910122 sender=:1.58 -> destination=org.mpris.MediaPlayer2.vlc serial=1878 path=/org/mpris/MediaPlayer2; interface=org.mpris.MediaPlayer2.Player; member=PlayPause
# so I piped together a few commands, which got the wrong dbus output, and forwarded it to spotify.
# run:
# bash spotify-media-key-fix.sh &
# edit: if u get error awk: option `-W interactive' unrecognized, ignored
# replace awk with mawk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment