diff options
Diffstat (limited to 'templates/.bin/get_volume')
-rwxr-xr-x | templates/.bin/get_volume | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/templates/.bin/get_volume b/templates/.bin/get_volume new file mode 100755 index 0000000..30516b0 --- /dev/null +++ b/templates/.bin/get_volume @@ -0,0 +1,36 @@ +#!/bin/bash +# Displays the default device, volume, and mute status for i3blocks + +set -a + +AUDIO_MUTED_SYMBOL= +AUDIO_SYMBOL= + +MIXER="default" +if amixer -D pulse info >/dev/null 2>&1 ; then + MIXER="pulse" +fi + +function print_block { + ACTIVE=$(pacmd list-sinks | grep "state\: RUNNING" -B4 -A7 | grep "index:\|name:\|volume: front\|muted:") + [ -z "$ACTIVE" ] && ACTIVE=$(pacmd list-sinks | grep "index:\|name:\|volume: front\|muted:" | grep -A3 '*') + for name in INDEX NAME VOL MUTED; do + read $name + done < <(echo "$ACTIVE") + INDEX=$(echo "$INDEX" | grep -o '[0-9]\+') + VOL=$(echo "$VOL" | grep -o "[0-9]*%" | head -1 ) + VOL="${VOL%?}" + + if [[ $MUTED =~ "no" ]] ; then + SYMB=$AUDIO_SYMBOL + else + SYMB=$AUDIO_MUTED_SYMBOL + fi + + echo "<span font='FontAwesome'>${SYMB}</span> ${VOL}%" +} + +print_block +while read -r EVENT; do + print_block +done < <(pactl subscribe | stdbuf -oL grep change) |