Created
May 7, 2024 17:19
-
-
Save sovietspy2/3849a997e057bee99a7a7dab40be2d71 to your computer and use it in GitHub Desktop.
Thinkpad T480 change audio output between BUILT IN SPEKER and HDMI
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 | |
# Define the card and its profiles | |
CARD="pci-0000_00_1f.3" | |
CARD_PROFILE_1="hdmi-stereo" # Profile 1 | |
CARD_PROFILE_2="analog-stereo" # Profile 2 | |
CURRENT_PROFILE=$(pacmd list-sinks | awk '/^\s*\* index:/{flag=1; next} flag && /active port:/{print $NF; exit}') | |
echo $CURRENT_PROFILE | |
# Function to set the profile based on the argument | |
set_profile() { | |
case $CURRENT_PROFILE in | |
"<hdmi-output-0>") | |
PROF="$CARD_PROFILE_2" | |
;; | |
"<analog-output-speaker>") | |
PROF="$CARD_PROFILE_1" | |
;; | |
*) | |
echo "Invalid profile argument. Exiting." | |
exit 1 | |
;; | |
esac | |
} | |
# Call the function to set the profile based on the argument | |
set_profile | |
# Set the chosen 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment