dwmb-volume (850B) - raw
1 #!/usr/bin/env bash 2 # Displays the default device, volume, and mute status for i3blocks 3 4 5 AUDIO_HIGH_SYMBOL="" 6 AUDIO_MED_SYMBOL="" 7 AUDIO_LOW_SYMBOL="" 8 AUDIO_MUTED_SYMBOL="" 9 10 AMIXER=$(amixer get Master | tail -n 1) # get last line of amixer output 11 12 # show either volume or mute 13 if [[ $AMIXER =~ "[on]" ]]; then # check if channel is muted by checking if line contains the word "on" 14 IFS=' ' read -ra args <<< "$AMIXER" # split string 15 16 VOL="${args[4]:1:-2}" # get 4th argument (the volume) from the string we just split and remove the first and last argument (square brackets) and the % at the end 17 18 if [ "$VOL" -le "0" ]; then 19 echo "$AUDIO_LOW_SYMBOL" 20 elif [ "$VOL" -le "50" ]; then 21 echo "$AUDIO_MED_SYMBOL $VOL%" 22 else 23 echo "$AUDIO_HIGH_SYMBOL $VOL%" 24 fi 25 else 26 echo "$AUDIO_MUTED_SYMBOL" 27 fi