Last active
September 1, 2025 13:20
-
-
Save dakhnod/ed004affba457fc0a84b8e7df64730b2 to your computer and use it in GitHub Desktop.
Script to pause and resume all playback on your linux computer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| busses=$(dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep -oP "(?<=string \")org.mpris.MediaPlayer2.*instance.*(?=\")") | |
| for bus in $busses; do | |
| dbus-send --print-reply --dest=$bus /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| if [[ $1 != "pause" && $1 != "resume" ]]; then | |
| echo "call with argument pause or resume" | |
| exit 1 | |
| fi | |
| mkdir -p /tmp/playbacks | |
| cd /tmp/playbacks | |
| busses=$(dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep -oP "(?<=string \")org.mpris.MediaPlayer2.*instance.*(?=\")") | |
| for bus in $busses; do | |
| if [[ $1 == "pause" ]]; then | |
| dbus-send --print-reply=literal --dest=$bus /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'PlaybackStatus' | grep -q Playing || continue | |
| position=$(dbus-send --print-reply=literal --dest=$bus /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Position' | grep -oP "(?<=int64 )[0-9]+") | |
| dbus-send --print-reply --dest=$bus /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause | |
| echo $position > $bus | |
| elif [[ $1 == "resume" ]]; then | |
| test -f $bus || continue # don't resume if file not present | |
| # comment the following line if you want to avoid the seeking | |
| dbus-send --print-reply --dest=$bus /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Seek int64:-10000000 | |
| dbus-send --print-reply --dest=$bus /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Play | |
| rm $bus | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment