0

I've read on this SO question: Set HDMI sound output automatically on connect/disconnect

But it does not work.

Using pactl set-card-profile 0 output:hdmi-stereo does not work on terminal even though the profile exists.

How to do it for Ubuntu 15.10?

zed
  • 551
  • 5
  • 9
  • Does the output work at all? – Daniel Jan 20 '16 at 19:54
  • Those scripts have been updated for more modern versions. They should work just fine for you/ – Daniel Jan 20 '16 at 19:55
  • Possible duplicate of [Set HDMI sound output automatically on connect/disconnect](https://askubuntu.com/questions/263248/set-hdmi-sound-output-automatically-on-connect-disconnect) – Tom Brossman Oct 29 '18 at 16:02
  • Possible duplicate of [Switch between internal and HDMI speakers automatically](https://askubuntu.com/questions/854055/switch-between-internal-and-hdmi-speakers-automatically) – karel Oct 30 '18 at 02:19

1 Answers1

1

Solved it.

I had to use pacmd set-default-sink rather than pactl set-card-profile. To be able to use it in a script, you must export PULSE_RUNTIME_PATH also. Create /usr/local/bin/hdmi_sound_toggle:

#!/bin/sh
HDMI_STATUS=`cat /sys/class/drm/card0/card0-HDMI-A-1/status`
export PULSE_RUNTIME_PATH="/run/user/1000/pulse/"

if [ $HDMI_STATUS = "connected" ]
then
    sudo -u zed -E pacmd set-default-sink 0
else
    sudo -u zed -E pacmd set-default-sink 1
fi

Where zed is my username and 1000 is my UID. chmod the file to 0755.

Create a udev rule at /etc/udev/rules.d/hdmi_sound.rule as sudo:

SUBSYSTEM=="drm", ACTION=="change", RUN+="/usr/local/bin/hdmi_sound_toggle"

Restart udev rules:

sudo udevadm control --reload 

You can test that the udev rules works using udevadm monitor --property.

zed
  • 551
  • 5
  • 9