Created
April 13, 2022 02:29
-
-
Save jared-hughes/5d303b911f038057f0d997ecb90c53dc to your computer and use it in GitHub Desktop.
Switch audio device
This file contains 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 | |
# Switch audio device | |
# Based on https://askubuntu.com/a/1203350/647230 | |
declare -i next_sink_index=`pacmd list-sinks | sed -n -e 's/[[:space:]][[:space:]]index:[[:space:]]\([[:digit:]]\)/\1/p'` | |
# Change the default sink | |
pacmd "set-default-sink ${next_sink_index}" | |
# Move all inputs to the new sink | |
for app in $(pacmd list-sink-inputs | sed -n -e 's/index:[[:space:]]\([[:digit:]]\)/\1/p'); | |
do | |
pacmd "move-sink-input $app $next_sink_index" | |
done | |
# Notify change | |
notify-send -i audio-headphones "Sound output switched to $(pacmd list-sinks | awk '/index: '"$next_sink_index"'/{f=1} /device.description/{if(f==1){print;f=0};}' | sed -n -e 's/\s*device.description = "\(.*\)".*/\1/p')" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment