Audio Device Changed Trigger on specific change

I have a TV in my office that I use for presentations. It's connected to my mac via Airplay. When I want to run a presentation to it I simply use Airplay to activate that apple tv as a separate display.

The problem is that my mac has really good speakers connected in the office and the tv does not. When airplay triggers it changes the audio source to it. Also if I forget to switch the audio back (usually if I wasn't using audio in the presentation) then later I have no sound because even though I may have deactivated airplay the sound is still being sent there.

I know there is a trigger for audio device changes, but I don't want it to do every time the audio device changes... just when it changes to the airplay output.

Also can't find an action to change the device.

Anyone know how to do that?

I'm afraid I don't have time to offer a more comprehensive solution at the moment, but I can demonstrate how I used the command-line utility switchaudio-osx in a macro to solve a similar problem with a DualShock 4 controller hijacking my Mac's audio output every time I plugged it in:

Stop DS4 From Intercepting Audio.kmmacros (2.9 KB)
image

The Pause Until action contains a simple script that lists every current audio output device currently connected, then moves ahead with the command to change the audio output device to the one I want once it has verified that the list contains the offending device. If you don't mind installing this command-line utility, you could try a similar macro that looks for the name of the output device used for AirPlay to change it to the output you want.