1
0
Fork 0
archlinux/home/oli/bin/i3blocks/mic_mute

44 lines
1.1 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# Shows microphone mute status for the default audio source.
# Left click toggles mute.
. ~/bin/i3blocks/_utils
# If wpctl get-volume @DEFAULT_AUDIO_SOURCE@ output doesn't start with
# "Volume" we consider no microphone is connected. This is hacky, but needed
# as wpctl doesn't RC != 0 when no mic is connected
mic_mute() {
if [[ "$BLOCK_BUTTON" == "1" ]]; then
wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle
fi
local wpctl_output
wpctl_output=$(wpctl get-volume @DEFAULT_AUDIO_SOURCE@ 2>/dev/null)
local muted
muted=$(echo "$wpctl_output" | grep -c '\[MUTED\]')
local bg fg icon stat
# If the output does NOT start with 'Volume:', no microphone is connected
if [[ ! "$(echo $wpctl_output)" =~ ^Volume ]]; then
bg=$mute_bg
fg=$mute_fg
stat="N/A"
else
if [[ "$muted" -ge 1 ]]; then
bg=$mute_bg
fg=$mute_fg
stat="MUT"
else
bg=$crit_bg
fg=$crit_fg
stat="REC"
fi
fi
echo -e "MIC <span background=\"$bg\" color=\"$fg\"> $stat </span>\n"
}
mic_mute