cat playerctl.sh
#!/usr/bin/env bash
# Check if a parameter is provided
if [ -z "$1" ]; then
echo "Please provide a command (n)ext, (pp)play-pause, (p)revious, (s)top)."
exit 1
fi
# Map input parameters to MPRIS commands
declare -A commands=(
["n"]="Next"
["pp"]="PlayPause"
["p"]="Previous"
["s"]="Stop"
)
# Find all MPRIS-compatible media player instances of Firefox
player=$(busctl --user list | grep 'org.mpris.MediaPlayer2.firefox' | awk '{print $1}')
echo $player
# Send the corresponding command to each found Firefox instance
for instance in $player; do
busctl --user call "$instance" /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player "${commands[$1]}"
done
edit
player=$(busctl --user list | grep 'org.mpris.MediaPlayer2' | awk '{print $1}')
to control all player at once
Comments
Post a Comment