I use TV connected by HDMI cable to my laptop.
I want to be able to quickly perform following operations:
- activate TV as main display and switch off the laptop screen,
- switch to the HDMI sound from sound speakers
as well as in reverse direction.
To do so, I wrote following bash script:
#!/bin/bash
# Switch between (HDMI output + HDMI sound) and (laptop display and laptop sound)
laptopDisp="eDP-1"
laptopSound="sound profile name returned by pacmd list-sinks | grep -e 'name:'"
hdmiDisp="HDMI-1"
hdmiSound="HDMI sound profile name returned by pacmd list-sinks | grep -e 'name:'"
currentDisplay=$(xrandr | grep " connected primary " | awk '{ print$1 }')
if [ "$currentDisplay" == "$laptopDisp" ]
then
echo "Switching on HDMI, switch off main display"
xrandr --output $hdmiDisp --auto
xrandr --output $laptopDisp --off
pacmd set-default-sink $hdmiSound
pulseaudio -k
else
echo "Switching off HDMI screen and set sound from laptop speakers:"
pacmd set-default-sink $laptopSound
xrandr --output $laptopDisp --auto
xrandr --output $hdmiDisp --off
pulseaudio -k
fi
When I run it, the primary screen is changed. Unfortunately, although in the sound control panel I see that sound source was changed, I cannot hear any sound from laptop speakers.
What could be the source of the issue?
0 Answers