#!/usr/bin/env bash # Displays the default device, volume, and mute status for i3blocks AUDIO_HIGH_SYMBOL="" AUDIO_MED_SYMBOL="" AUDIO_LOW_SYMBOL="" AUDIO_MUTED_SYMBOL="" AMIXER=$(amixer get Master | tail -n 1) # get last line of amixer output # show either volume or mute if [[ $AMIXER =~ "[on]" ]]; then # check if channel is muted by checking if line contains the word "on" IFS=' ' read -ra args <<< "$AMIXER" # split string 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 if [ "$VOL" -le "0" ]; then echo "$AUDIO_LOW_SYMBOL" elif [ "$VOL" -le "50" ]; then echo "$AUDIO_MED_SYMBOL $VOL%" else echo "$AUDIO_HIGH_SYMBOL $VOL%" fi else echo "$AUDIO_MUTED_SYMBOL" fi