Skip to content

Instantly share code, notes, and snippets.

@lovromazgon
Last active March 13, 2024 11:02
Show Gist options
  • Save lovromazgon/d4681b13469f3f3921c1f26af5e7ae38 to your computer and use it in GitHub Desktop.
Save lovromazgon/d4681b13469f3f3921c1f26af5e7ae38 to your computer and use it in GitHub Desktop.
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