omarchy/bin/omarchy-cmd-audio-switch
Christopher 8c1fd76a37
Add SUPER + MUTE for audio output switching (#941)
* Add SUPER + MUTE for audio output switching

* Fix migration bc stupidness

* Simplify implementation and ensure the new sink is not muted

---------

Co-authored-by: David Heinemeier Hansson <david@hey.com>
2025-08-22 20:43:46 +02:00

20 lines
663 B
Bash
Executable File

#!/bin/bash
# Find all the audio sinks but exit if there are none
sinks=($(wpctl status | sed -n '/Sinks:/,/Sources:/p' | grep -E '^\s*│\s+\*?\s*[0-9]+\.' | sed -E 's/^[^0-9]*([0-9]+)\..*/\1/'))
[ ${#sinks[@]} -eq 0 ] && exit 1
# Find current audio sink
current=$(wpctl status | sed -n '/Sinks:/,/Sources:/p' | grep '^\s*│\s*\*' | sed -E 's/^[^0-9]*([0-9]+)\..*/\1/')
# Find the next sink (looping around in the list)
for i in "${!sinks[@]}"; do
[ "${sinks[$i]}" = "$current" ] && next=${sinks[$(((i + 1) % ${#sinks[@]}))]}
done
next=${next:-${sinks[0]}}
# Set the next sink and ensure it's not muted
wpctl set-default "$next"
wpctl set-mute "$next" 0