#!/bin/sh usage () { cat <&2 Usage: ${0##*/} This script will toggle HDMI Audio (and set video properly). To do this automatically when the cable is plugged, add the following udev rule: $ cat /etc/udev/rules.d/hdmi.rules SUBSYSTEM=="drm", ACTION=="change", RUN+="/bin/sh $0" To get audio working on radeon, you may need to boot with the following kernel paremeter: radeon.audio=1 You must be root. This script is Linux only. EOF } if [ "$(uname)" != "Linux" ]; then usage exit 1 fi if [ "$(id -u)" -ne 0 ]; then usage exit 1 fi ALSACONF="/etc/asound.conf" HDMI_STATUS="$(cat /sys/class/drm/card0-HDMI-A-1/status)" [ -z "$HDMI_STATUS" ] && exit APLAY_BUF="$(aplay -l | grep HDMI)" getprop () { echo "$APLAY_BUF" | awk -v prop="$1" '{for(i=1; i "$ALSACONF" pcm.!default { type hw card $CARD device $DEVICE } EOF chmod 644 "${ALSACONF}" echo "HDMI sound enabled" else rm -f "$ALSACONF" echo "HDMI sound disabled" fi