wren-linux / bin / volume
#!/bin/sh
# volume up|down|mute|micmute [STEP]: written by Wren Linux extras/pipewire-audio.sh
# Changes the sound volume by STEP percent (default 5), never above 100%,
# turns the sound back on if it was muted, then tells sway-status to redraw
# the bar.
step=${2:-5}
case $step in '' | *[!0-9]*) echo "usage: volume up|down|mute|micmute [STEP]" >&2; exit 2 ;; esac
sink=@DEFAULT_AUDIO_SINK@
case $1 in
up) wpctl set-mute "$sink" 0; wpctl set-volume -l 1.0 "$sink" "$step%+" ;;
down) wpctl set-mute "$sink" 0; wpctl set-volume "$sink" "$step%-" ;;
mute) wpctl set-mute "$sink" toggle ;;
micmute) wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle ;;
*) echo "usage: volume up|down|mute|micmute [STEP]" >&2; exit 2 ;;
esac
# Only signal it if that PID really is sway-status (a stale file could
# point at an unrelated process, which SIGUSR1 would kill)
pid=$(cat "${XDG_RUNTIME_DIR:-/tmp}/sway-status.pid" 2>/dev/null)
if [ -n "$pid" ] && tr '\0' ' ' <"/proc/$pid/cmdline" 2>/dev/null | grep -q sway-status; then
kill -USR1 "$pid" 2>/dev/null
fi
exit 0