Created
April 3, 2020 19:22
-
-
Save bse666/f84c31bb8dddfe24e253a2568bbcdd3e to your computer and use it in GitHub Desktop.
Pulseaudio Soundcard Switcher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
outputsinks=$(pacmd list-sinks | grep index | awk '{print $NF}') | |
defaultsink=$(pacmd list-sinks | grep index | grep \* | awk '{print $NF}'| tr -d "[[:space:]]") | |
for i in ${outputsinks[@]/$defaultsink/}; | |
do | |
newOutputIndex=$i | |
done | |
playbackStreams=$(pacmd list-sink-inputs | grep "index" | cut -c 12-) | |
readarray -t playbackStreams <<<"$playbackStreams" | |
if [ "$playbackStreams" = "" ]; then | |
pacmd set-default-sink $newOutputIndex | |
else | |
for stream in "${playbackStreams[@]}" | |
do | |
pacmd move-sink-input $stream $newOutputIndex | |
done | |
pacmd set-default-sink $newOutputIndex | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment