Automatic sound switch to HDMI when plugged in

Report Bugs, Issues and non- package Requests
Message
Author
jerem_
Posts: 4
Joined: Sun Apr 18, 2021 3:26 am

Automatic sound switch to HDMI when plugged in

#1 Post by jerem_ »

Hi,

Is there any general and clean way to switch the sound output to HDMI when a HDMI is plugged in?
I can write a bash script but a prefer a cleaner solution if possible.

Thanks!

User avatar
Michael-IDA
Posts: 359
Joined: Sat Jan 12, 2019 8:00 pm

Re: Automatic sound switch to HDMI when plugged in

#2 Post by Michael-IDA »

I'd like to be able to do this as well.

Following...
NIH Cancer Study: The group supplemented with both vitamins and fenbendazole exhibited significant (P = 0.009) inhibition of tumor growth.
The day Microsoft makes a product that doesn't suck...
... is the day they make a vacuum cleaner.

jerem_
Posts: 4
Joined: Sun Apr 18, 2021 3:26 am

Re: Automatic sound switch to HDMI when plugged in

#3 Post by jerem_ »

I wrote this dirty but effective script and add it to a launcher in my upper panel. You have to check the "launch in terminal" to be able to see the messages. I just have to click on the launcher when I need to switch.
You may need to change some stuff depending on your profiles and outputs...

#!/bin/bash
actstereo=$(pacmd list |grep 'active profile' | grep 'output:analog-stereo+input:analog-stereo')
hdmiact=$(pacmd info | grep 'hdmi-output-1' | grep 'yes')

# Switch to Analog Stereo Duplex profile if another profile is active
if [[ -z $actstereo ]]; then
echo "Switch to Analog Stereo Duplex"
pacmd set-card-profile 0 output:analog-stereo+input:analog-stereo
# If HDMI is available, switch to it
elif [[ -n $hdmiact ]]; then
echo "Switch to HDMI output"
pacmd set-card-profile 0 output:hdmi-stereo-extra1+input:analog-stereo
# Otherwise, stick to Analog Stereo Duplex
else
echo "Analog Stereo Duplex already active"
fi

sleep 1

User avatar
JayM
Posts: 6796
Joined: Tue Jan 08, 2019 3:47 am

Re: Automatic sound switch to HDMI when plugged in

#4 Post by JayM »

See the MX Wiki: https://mxlinux.org/wiki/hardware/sound-not-working/
For automatic switching to HDMI when connected, consult this GitHub script.
Please read the Forum Rules, How To Ask For Help, How to Break Your System and Don't Break Debian. Always include your full Quick System Info (QSI) with each and every new help request.

Post Reply

Return to “Bugs and Non-Package Requests Forum”