From 1ae5212241e9336da900110297caaa37f85e05f4 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 16 Nov 2022 21:30:06 -0500 Subject: [PATCH] Fix waybar sound script on linux when muted. --- ansible/roles/sway/files/waybar_sound_linux.bash | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ansible/roles/sway/files/waybar_sound_linux.bash b/ansible/roles/sway/files/waybar_sound_linux.bash index 08f3101..46313f7 100644 --- a/ansible/roles/sway/files/waybar_sound_linux.bash +++ b/ansible/roles/sway/files/waybar_sound_linux.bash @@ -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="$(wpctl status)" tooltip=${tooltip//$'\n'/\\n} tooltip=${tooltip//$'\t'/\\t}