I have written a script that changes my display output from DVI (my monitor) to HDMI (my TV) by using xrandr. In this script, I would also like to change my audio output from analog line out to HDMI.
I have tried the following:
pacmd set-default-sink alsa_output.pci-0000_01_00.1.hdmi-stereo-extra1
This seems to change some sounds (like the sound you hear when you adjust volume on the desktop) to hdmi, but still the default sound output for applications (like Steam big picture mode and various games) is set to analog. To change it to HDMI, I need to click the sound settings panel on the desktop and change it manually to HDMI.
How do I change the sound output from the command line reliably? Or alternatively, what exactly does Ubuntu sound settings do under the hood when I change the sound output?
I'm running Ubuntu 15.10.