1

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:

  1. 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.

  2. 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?

PiotrSz
  • 11
  • 1
    Welcome to Ask Ubuntu! ;-) Could you please give us a bit more information like: Does the echo work in both cases when you change your script to the above? Please [edit] your question and add this information... – Fabby Mar 08 '15 at 19:22

1 Answers1

0

Read this post it worked for me... Unable to get audio through HDMI connection to TV with Ubuntu 14.04

$ sudo adduser your_linux_user_name

Todd
  • 281