I’m a big fan of Rogue Amoeba and their excellent audio tools. I use SoundSource to route audio from particular macOS apps to specific output devices at specific volumes. Excitingly, they’ve just added Shortcuts-based automation
I’ve written a Shortcut to change the output device and volume for a particular application and Keyboard Maestro macros to call them. I use this as part of a chain of macros when I swap between different audio contexts (from a conference call to listening to music, say).
For more details, see my post on the Keyboard Maestro forums. (I hope it’s ok to link to it rather than duplicate it here, so that I don’t have to update any changes in both forums). The macro uses the native new Execute Shortcut action in KM v10.1 which allows a KM macro to call a Shortcut with parameters.
It’s my first real experience with anything other than a trivial Shortcut, and I’d welcome any constructive criticism from the experts here