From c09d91fe95fca4367f47c06fc808cd02a1a8e6a5 Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Tue, 13 Aug 2019 14:40:54 -0400 Subject: add bins --- templates/.bin/get_volume | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 templates/.bin/get_volume (limited to 'templates/.bin/get_volume') 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 "${SYMB} ${VOL}%" +} + +print_block +while read -r EVENT; do + print_block +done < <(pactl subscribe | stdbuf -oL grep change) -- cgit v1.2.3