Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script for switching between 2 audio sinks
#!/bin/bash
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
next_sink=0
fi
# 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
You can’t perform that action at this time.