#!/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 "${SYMB} ${VOL}%" } print_block while read -r EVENT; do print_block done < <(pactl subscribe | stdbuf -oL grep change)