From 1b0f8a325c054cf8f760655d2e2aff131cb73071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Dudr?= Date: Fri, 16 Dec 2022 22:30:42 +0100 Subject: [PATCH] scripts: add mpristoggle --- bin/executable_mpristoggle | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 bin/executable_mpristoggle diff --git a/bin/executable_mpristoggle b/bin/executable_mpristoggle new file mode 100644 index 0000000..cf3ebed --- /dev/null +++ b/bin/executable_mpristoggle @@ -0,0 +1,26 @@ +#!/bin/zsh + +declare -i count=0 +declare -i playing=0 + + +while read player ps +do + count+=1 + [[ "$ps" == Playing ]] && playing+=1 +done < <(playerctl -a status --format '{{playerName}} {{status}}') + +case $count in + 0) notify-send -t 800 -a "Player toggle" "No player running" ;; + 1) playerctl play-pause ;; + *) + if ((playing > 0)) + then + playerctl pause -a + else + player=$(playerctl status -a --format '{{playerName}} ({{status}})' | rofi -dmenu -p "Play: ") + # pouzit prvni slovo, podle shell pravidel... + # jsou vsechny prehravace se jednoslovnym nazvem? + [[ -n "$player" ]] && playerctl -p "${${(z)player}[1]}" play + fi +esac