
Also not 100% sure on the security Nevertheless, I hope it helps some folks. I'm guessing it has something to do with calling the "System Events" application but I'm not 100% on that.

One downside to this approach is that you have to grant "Control your computer" access for any app that calls this workflow / quick action. Just change the sourceToChange variable from "Output" to "Input" if you'd like to make another script for swapping microphone sources. Check out this page in the macOS User Guide: If your Mac switches to a different audio device - Apple Support. So I wrote the below which will simply loop through all of the options and select the next source in the list / the first source in the list if the last option is selected. It sounds like you're familiar with changing the sound output in System Preferences, as discussed here: Change the sound output settings on Mac - Apple Support.

Not to mention if the source is not always in the output list (e.g. Also I couldn't find an elegant solution for swapping between 3 audio outputs using if-else.

I needed a keyboard shortcut for changing my sound output - I liked the simplicity of the AppleScript answers I've seen on the Stack Exchange forums, but I don't like the idea of having to hardcode the output/input device name I want to change.
