change audio output

This commit is contained in:
ltadeu6 2026-04-01 10:01:10 -03:00
parent 450754b39a
commit 45be1fbdd7
2 changed files with 37 additions and 0 deletions

View file

@ -127,6 +127,7 @@
}, },
"scroll-step": 10, "scroll-step": 10,
"on-click": "pavucontrol", "on-click": "pavucontrol",
"on-click-right": "./switch_sink.sh",
"ignored-sinks": ["Easy Effects Sink"], "ignored-sinks": ["Easy Effects Sink"],
"tooltip-format": "{icon} {volume}" "tooltip-format": "{icon} {volume}"
}, },

36
waybar/switch_sink.sh Executable file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env sh
# Cycle default sink and move existing inputs.
if ! command -v pactl >/dev/null 2>&1; then
exit 1
fi
current="$(pactl get-default-sink 2>/dev/null)"
[ -z "$current" ] && exit 1
sinks="$(pactl list short sinks | awk '{print $2}')"
[ -z "$sinks" ] && exit 1
next=""
found=0
for s in $sinks; do
if [ "$found" -eq 1 ]; then
next="$s"
break
fi
if [ "$s" = "$current" ]; then
found=1
fi
done
# If current is last or not found, wrap to first.
if [ -z "$next" ]; then
next="$(printf '%s\n' "$sinks" | head -n 1)"
fi
pactl set-default-sink "$next" || exit 1
# Move existing audio streams to the new sink.
for input in $(pactl list short sink-inputs | awk '{print $1}'); do
pactl move-sink-input "$input" "$next" >/dev/null 2>&1 || true
done