Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Script for switching between 2 audio sinks
set -euo pipefail # strict mode
currentSink() { pacmd list-sinks | awk '{if($1=="*"){print $3;}}'; }
inactiveSink() { pacmd list-sinks | awk '{if($1=="index:"){print $2;}}'; }
sinkInputs() { pacmd list-sink-inputs | awk '{if($1=="index:")print $2}'; }
current_sink="$(eval currentSink)"
inactive_sink="$(eval inactiveSink)"
sink_inputs="$(eval sinkInputs)"
let next_sink=current_sink+1
if [[ $inactive_sink != *"$next_sink"* ]]; then
# set the inactive sink as default for new streams
pacmd set-default-sink "$next_sink"
while read -r input; do
# move existing stream to inactive sink
pacmd move-sink-input "$input" "$next_sink"
done <<< "$sink_inputs"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment