Thursday, May 9, 2024
 Popular · Latest · Hot · Upcoming
9
rated 0 times [  9] [ 0]  / answers: 1 / hits: 17350  / 2 Years ago, sun, july 31, 2022, 7:14:58

I'm trying to get my laptop to switch the audio to HDMI when it's plugged in, and back to standard analog when it's removed.



I set up a udev rule to trigger a script to perform the switching, however I'm having problems getting it to work:




  • It appears that until I select the HDMI Audio output in the Sound Settings, it is not recognised as a available sink, also once the HDMI Audio output is selected, the analog output is no longer listed.



See the below:



# HDMI plugged in, not selected in Sound settings.
$ pactl list short sinks
5 alsa_output.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
kingamajick@kingamajick-laptop: ~

# HDMI selected in sound settings
$ pactl list short sinks
7 alsa_output.pci-0000_00_1b.0.hdmi-stereo module-alsa-card.c s16le 2ch 48000Hz SUSPENDED
kingamajick@kingamajick-laptop: ~

# HDMI removed
$ pactl list short sinks
9 alsa_output.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 48000Hz SUSPENDED


The script I'm using the toggle the output is as follows:



#!/bin/bash
HDMI_STATUS=`cat /sys/class/drm/card0/*HDMI*/status`
INPUTS=($(pacmd list-sink-inputs | grep index | awk '{print $2}'))

if [ $HDMI_STATUS = "connected" ]
then
pactl set-default-sink alsa_output.pci-0000_00_1b.0.hdmi-stereo
for i in ${INPUTS
  • }; do pacmd move-sink-input $i alsa_output.pci-0000_00_1b.0.hdmi-stereo &> /dev/null; done
    else
    pactl set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo
    for i in ${INPUTS
  • [*]}; do pacmd move-sink-input $i alsa_output.pci-0000_00_1b.0.analog-stereo &> /dev/null; done-server $PULSE_SERVER set-card-profile 0 output:analog-stereo+input:analog-stereo
    fi


    The script gives an error about no such sink when I trigger it before I select HDMI in the sound settings.


    More From » sound

     Answers
    2

    1. Check for available cards & profiles



      pactl list cards

    2. Add following command to the script to change profile before setting default sink & moving streams



      pactl [options] set-card-profile  CARD PROFILE



    (So no need to switch it manually from Sound Settings)



    Reference:



    pactl -h & man pactl


    [#25542] Tuesday, August 2, 2022, 2 Years  [reply] [flag answer]
    Only authorized users can answer the question. Please sign in first, or register a free account.
    initiallartebeest

    Total Points: 24
    Total Questions: 118
    Total Answers: 105

    Location: Venezuela
    Member since Thu, Jul 15, 2021
    3 Years ago
    ;