dotfiles/config/polybar/scripts/pulse-microphone.sh

60 lines
1.2 KiB
Bash
Raw Permalink Normal View History

2023-03-09 10:21:15 +01:00
#!/bin/sh
status() {
MUTED=$(pacmd list-sources | awk '/\*/,EOF {print}' | awk '/muted/ {print $2; exit}')
if [ "$MUTED" = "yes" ]; then
echo "🙊 muted"
else
OUTPUT=$(pacmd list-sources | grep "\* index:" -A 7 | grep volume | awk -F/ '{print $2}' | awk -F, '{ print $1 }' | tr -d ' ')
echo "🎙️ $OUTPUT"
fi
}
listen() {
status
LANG=EN
pactl subscribe | while read -r event; do
if echo "$event" | grep -q "source" || echo "$event" | grep -q "server"; then
status
fi
done
}
toggle() {
MUTED=$(pacmd list-sources | awk '/\*/,EOF {print}' | awk '/muted/ {print $2; exit}')
DEFAULT_SOURCE=$(pacmd list-sources | awk '/\*/,EOF {print $3; exit}')
if [ "$MUTED" = "yes" ]; then
pactl set-source-mute "$DEFAULT_SOURCE" 0
else
pactl set-source-mute "$DEFAULT_SOURCE" 1
fi
}
increase() {
DEFAULT_SOURCE=$(pacmd list-sources | awk '/\*/,EOF {print $3; exit}')
pactl set-source-volume "$DEFAULT_SOURCE" +5%
}
decrease() {
DEFAULT_SOURCE=$(pacmd list-sources | awk '/\*/,EOF {print $3; exit}')
pactl set-source-volume "$DEFAULT_SOURCE" -5%
}
case "$1" in
--toggle)
toggle
;;
--increase)
increase
;;
--decrease)
decrease
;;
*)
listen
;;
esac