I sometimes have my headphones plugged in but not wearing them and I would like a notification sound to be played on the speaker system, is there anyway to do this?
That's an interesting question. So I think what you are asking is for the ability for a specific macro to override, ignore or change the output device for sound. Or do you want this macro to display its audio into the headphones if the headphones are being used? That's a different problem, but not unsolvable!!! You are probably asking yourself? How do you tell if the headphones are being used? Trust me, there's a way to do that. I can think of two ways to do that. (Correction: 3 ways.)
If the goal is just to change the sound output device, there are probably several different ways to achieve this. One way is to get your macro to check what the current sound output device is, and either change it temporarily or permanently when it needs to make a sound. This can be done either through manipulating the System preferences panel with your macro or probably through some shell commands from the Execute Shell action.
There's a definite possibility that AppleScript has some built-in ways to examine and modify these system preferences but I don't give advice on AppleScript because I'm so lame at it. It might be the best solution, but I can't advise you on that.
To recap: The first option is manipulating the System Preferences with a KM macro. The second is to manipulate macOS using shell commands. And the third is to use AppleScript to do the same thing. Which approach appeals to you the most?
There's a fourth option which is to take advantage of amazing Sound Device features in a software product called Audio Hijack Pro. I've used KM to manipulate it, for a different purpose that what you are doing, but I think it might work here too.
There might be a fifth option which is to find some feature in macOS that supports this, but I'm not aware of that. Well, read this article for clues on how that could be done. It doesn't directly address your problem but it might give you a lead for further ideas.
I should have clarified I was hoping to use the mac's internal speaker system, not a bluetooth or other speaker.
I just realized I don't even know how to do this manually though, it seems as if it's not possible.
I know that you meant that, but the article shows that it is possible with macOS to get two different sounds devices to receive audio output at the same time. So the principle of dual device support exists inside macOS. I thought that might provide a lead for further research. How about those other four ideas I listed?