# Name: /usr/local/bin/audioswitch # Usage: audioswitch; audioswitch 1; audioswitch 2; audioswitch 3; audioswitch 4 #inspiré de https://askubuntu.com/questions/1011806/how-do-i-switch-the-audio-outputs-of-an-audio-device-from-cli # pactl list cards # pactl list sinks short # pacmd list-sinks | grep name: # Partie du(des) profil(s) : output:hdmi-stereo, output:hdmi-stereo+input:analog-stereo, output:hdmi-surround, output:hdmi-surround+input:analog-stereo, output:hdmi-surround71, output:hdmi-surround71+input:analog-stereo CARD_1="pci-0000_00_1b.0" CARD_1_PROFILE_1="hdmi-surround71" CARD_1_PROFILE_2="hdmi-stereo" # Read the user's input CHOICE="${@}" choice() { if [ "$CHOICE" == 1 ]; then CARD="$CARD_1"; PROF="$CARD_1_PROFILE_1" # LG ULTRAWIDE elif [ "$CHOICE" == 2 ]; then CARD="$CARD_1"; PROF="$CARD_1_PROFILE_2" # LG TV else echo -e "\nYou should choice between:" echo -e "\n\t[1] HDMI 7+1\n\t[2] HDMI STEREO\n" echo -n "Your choice: "; read CHOICE; echo; choice; # call the function again fi }; choice # call the function # Set the choosen card profile as sink pactl set-card-profile "alsa_card.${CARD}" "output:${PROF}"; # Set the default sink to the new one pacmd set-default-sink "alsa_output.${CARD}.${PROF}" &> /dev/null # Redirect the existing inputs to the new sink for i in $(pacmd list-sink-inputs | grep index | awk '{print $2}'); do pacmd move-sink-input "$i" "alsa_output.${CARD}.${PROF}" &> /dev/null done