suckless/bar/scripts/sb-volume
2025-05-25 17:58:23 +02:00

35 lines
809 B
Bash
Executable file

#!/bin/sh
# Prints the current volume or 🔇 if muted.
case $BLOCK_BUTTON in
1) wpctl set-volume @DEFAULT_SINK@ 1%+ ;;
2) wpctl set-mute @DEFAULT_SINK@ toggle ;;
3) wpctl set-volume @DEFAULT_SINK@ 1%- ;;
6) setsid -w -f "${TERMINAL:-st}" -e pulsemixer; pkill -RTMIN+3 "${STATUSBAR:-dwmblocks}" ;;
esac
vol="$(wpctl get-volume @DEFAULT_AUDIO_SINK@ 2>/dev/null || echo 0)"
# If muted, print 🔇 and exit.
[ "$vol" != "${vol%\[MUTED\]}" ] && echo 🔇 && exit
vol="${vol#Volume: }"
split() {
# For ommiting the . without calling and external program.
IFS=$2
set -- $1
printf '%s' "$@"
}
vol="$(printf "%.0f" "$(split "$vol" ".")")"
case 1 in
$((vol >= 70)) ) icon="🔊" ;;
$((vol >= 30)) ) icon="🔉" ;;
$((vol >= 1)) ) icon="🔈" ;;
* ) echo 🔇 && exit ;;
esac
echo "$icon$vol%"