citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

commit 48e018b2769e6da7854cfd9db34347d8e8439e18
parent 28e43d1114dd2497b0b4e29ae68cb5351e08ad8c
Author: William Casarin <jb55@jb55.com>
Date:   Tue,  4 Jan 2022 11:00:20 -0800

playpause: be smarter about pausing

Look for a service that is currently playing instead of prompting for
all services to potentially pause

Diffstat:
Mbin/spotify-playpause | 23++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/bin/spotify-playpause b/bin/spotify-playpause @@ -2,6 +2,14 @@ set -eou pipefail +playstatus() { + dbus-send --print-reply --dest="$1" /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:PlaybackStatus | sed -En 's,.*string "([^"]+)".*,\1,p' +} + +playpause() { + dbus-send --print-reply --dest="$1" /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause +} + bus=$(dbus-send \ --print-reply=literal \ --dest=org.freedesktop.DBus \ @@ -10,20 +18,25 @@ bus=$(dbus-send \ org.freedesktop.DBus.ListNames | tr ' ' '\n' | grep 'org.mpris.MediaPlayer2' | - grep -v qutebrowser + grep -v -e qutebrowser -e chromium ) count=$(wc -l <<<"$bus") -playpause() { - dbus-send --print-reply --dest="$1" /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause -} - if [ $count -eq 1 ]; then playpause "$bus" exit 0 fi +# auto-detect any source that is playing and then pause that +for b in $bus +do + if [ "$(playstatus "$b")" = "Playing" ]; then + playpause "$b" + exit 0 + fi +done + bus=$(<<<"$bus" sed 's,^org.mpris.MediaPlayer2.,,g' | dmenu -i -p "playpause" -l 7) playpause "org.mpris.MediaPlayer2.$bus"