Fix waybar sound script on linux when muted.

This commit is contained in:
Tom Alexander 2022-11-16 21:30:06 -05:00
parent f3edf7d8c1
commit 1ae5212241
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
#
# Read volume status in FreeBSD
# Read volume status in Linux
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
@ -9,8 +9,12 @@ SLEEP_INTERVAL=${SLEEP_INTERVAL:-30}
while true; do
current_vol_decimal=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | sed 's/Volume: //g')
current_vol_percent=$(bc -s <<<"$current_vol_decimal * 100")
current_vol_percent=${current_vol_percent%.*} # Remove decimal
if [[ "$current_vol_decimal" = *MUTED* ]]; then
current_vol_percent=0
else
current_vol_percent=$(bc -s <<<"$current_vol_decimal * 100")
current_vol_percent=${current_vol_percent%.*} # Remove decimal
fi
tooltip="<tt>$(wpctl status)</tt>"
tooltip=${tooltip//$'\n'/\\n}
tooltip=${tooltip//$'\t'/\\t}