I carry my laptop between home and work, and plug it into USB-C docks with all the peripherals attached, with different monitors in each place. I have recently upgraded my home setup with an AV receiver so video and sound now both go out via HDMI. At work sound still goes out via the analog port. Now when I plug in I have to manually change the audio output every time. So I wonder if an audio output could be associated with a display configuration so the switch is automatic.
I fear that is not going to happen. You may find this scriptable using pactl and kscreen-doctor or similar tools.
Looking into that I find that just getting the name of the connected monitor is rather involved. Is there a simple way? How does kscreen do it?