Prevent external speakers in monitors connected via HDMI being used

I sometimes run into an issue where I connect an external monitor via HDMI, and my Macbook Pro's sound is now routed to the monitor instead of my headphones or the internal speakers. Worse, sometimes this means that the volume control buttons stop working (even mute!)

I never, ever, want sound going through an external monitor. The internal speakers are better than most monitor speakers, anyway.

Is there a way to prevent this happening?


Solution 1:

In the sound section of system preferences, make sure that "Internal Speakers" is selected.

enter image description here

Solution 2:

I made an app for this. It allows you to pin input/output so it cannot be changed for every particular set of connected devices.