Skip to content

Instantly share code, notes, and snippets.

@ayosec
Created October 5, 2020 04:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayosec/bf6f608c3c4871325293d1ea43e8452e to your computer and use it in GitHub Desktop.
Save ayosec/bf6f608c3c4871325293d1ea43e8452e to your computer and use it in GitHub Desktop.
playerctl: skip metada to control music
#!/bin/bash
set -euo pipefail
case "${1:-}" in
next)
MEMBER=Next
;;
previous)
MEMBER=Previous
;;
play)
MEMBER=Play
;;
pause)
MEMBER=Pause
;;
play-pause)
MEMBER=PlayPause
;;
*)
echo "Usage: $0 next|previous|play|pause|play-pause"
exit 1
;;
esac
exec dbus-send \
--print-reply \
--dest="org.mpris.MediaPlayer2.$(playerctl -l | head -n 1)" \
/org/mpris/MediaPlayer2 \
"org.mpris.MediaPlayer2.Player.$MEMBER"
@sayan01
Copy link

sayan01 commented Nov 19, 2023

Why is line 34 required? The command seems to not work without it.

@ayosec
Copy link
Author

ayosec commented Nov 20, 2023

Why is line 34 required? The command seems to not work without it.

I guess that it depends on the player. I'm using this script with an old version of spotifyd. If I remove the --print-reply option, the action is not executed.

@sayan01
Copy link

sayan01 commented Nov 20, 2023

Why is line 34 required? The command seems to not work without it.

I guess that it depends on the player. I'm using this script with an old version of spotifyd. If I remove the --print-reply option, the action is not executed.

Yes, even for me (latest version of spotifyd) it does not work, but I was unable to understand why not printing the reply makes it not work, maybe something to do with dbus or spotifyd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment