I was annoyed that every time I connect my hdmi cable I need to manually change the sound setting.
I started looking into udev rules, what I came out with are these two files:
/etc/udev/rules.d/99-hdmi_sound.rules
SUBSYSTEM=="drm", RUN+="/lib/udev/hdmi_sound_toggle.sh"
/lib/udev/hdmi_sound_toggle.sh
:
#!/bin/bash
HDMI_STATUS=`cat /sys/class/drm/card0/*HDMI*/status`
if [ $HDMI_STATUS = "connected" ]
then
sudo -u root pactl set-card-profile 0 output:hdmi-stereo
else
sudo -u root pactl set-card-profile 0 output:analog-stereo
fi
When I'm running hdmi_sound_toggle.sh in the terminal, it works. It does not auto-run, though.
What am I doing wrong?