#!/bin/sh ## This script is Linux only. ## ## 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 /usr/local/bin/hdmi-switch" ## ## To get audio working on radeon, you may need to boot with the following ## kernel paremeter: ## ## radeon.audio=1 if [ $(id -u) -ne 0 ]; then echo "You must be root to run this script." exit fi ALSACONF="/etc/asound.conf" HDMI_STATUS="$(cat /sys/class/drm/card0-HDMI-A-1/status)" [ -z "$HDMI_STATUS" ] && exit BUF="$(aplay -l | grep HDMI)" _getprop() { echo "$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