3

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?

guy
  • 141
  • 5

2 Answers2

0

Have you tried reloading udev? It should recognise new rules automatically, but maybe it didn't...

sudo udevadm control --reload-rules ; sudo udevadm trigger

0
  • Try rename it to 99-hdmi_sound.rules (with 2 digits only)
  • & use RUN instead and omit ACTION

    SUBSYSTEM=="drm", RUN+="/lib/udev/hdmi_sound_toggle.sh"
    
  • It could be an environment problem (not same user, or undeclared env variables). Try adding some echo or touch commands to trace your script. Example:

    echo `date --rfc-3339='ns'` START >> /home/<your-username>/Desktop/udev_test_log.txt
    

    Put one in beginning, end, inside if, else ...

user.dz
  • 49,176