I have Ubuntu 14.04 LTS. I have an issue with switching audio output to HDMI when an external monitor (TV) is connected.
Here is my setup:
I created "udev rule" 10-hdmi_sound.rules in
/etc/udev/rules.d/
KERNEL=="card0", SUBSYSTEM=="drm", ACTION=="change", RUN+="/home/basia/test.sh"
I checked this rule carefully. It triggers test.sh every time HDMI cable is connected/ disconnected.
My
test.sh
is as follows:#!/bin/sh HDMI_STATUS=cat /sys/class/drm/card0/card0-HDMI-A-1/status if [ $HDMI_STATUS = "connected" ] ; then echo 'test' >> /home/user/connected.log sudo -u user pactl set-card-profile 0 output:hdmi-stereo else echo 'test' >> /home/user/disconnected.log sudo -u user pactl set-card-profile 0 output:analog-stereo fi
The script doesn't switch audio output when it's triggered from the udev rule, but works correctly when it's called manually. Echo works fine all the time - nevermind how script is called, from udev rule or manually. It seems there is an issue with "sudo -u user pactl set-card-profile ..." when script is called automatically.
Could you please help me with this issue?