Does anyone know if is possible to use keyboard maestro or another tool like BTT? I've tried all sorts of apple script and other things and can't get it to work. The end goal I'm trying to accomplish is is to have a button on my streamdeck that connects and Disconnects to a an AirPlay TV named "Sales Lounge".
If you don't mind a solution that uses the macOS GUI, then just tell me how you can do it with the GUI and I can draft a macro for you. But if what you want is a solution that works behind the scenes, without manipulating the macOS GUI, then you will have to wait for an AppleScript expert here. Since you didn't say whether you want it to work "silently" behind the GUI, I'm not sure which direction to go here.
If it can work in the background that would be ideal, but I'm open to any solution if it gets the intended outcome.
Ok.
The first time you mirror to your Apple TV, you may get some extra questions that you will not get on subsequent mirror attempts. I'm writing the macro now, but I assume that you have already done mirroring once and you have already selected your preferences. My macro might not be compatible with all possible mirroring options.
Yes, Ive connected to the display before and have it set how I want is. Just need it to connect to the screen since I'm constantly having to present things to other people.
Ok, I've got it to work for me. My Apple TV's name is "TV". The first line in my macro allows you to change it to "Sales" or whatever. It may require some touch-ups to work for you, like the screen captures, which you will see in my macro.
I have no concerns if you don't like my solution. I agree it's not a perfect solution, since it uses the GUI, but at least it works. I liked this puzzle. I'll upload it in a moment.
Here it is... Feel free to demand an AppleScript version, which may be possible and should work better, but I can't write AppleScript yet.
Mirror Macro (v11.0.3)
Mirror.kmmacros (70 KB)
You might have questions, so feel free to ask.
Yes, my macro actually does "toggle" the mirroring, as you requested. But it's up to you to attach this macro to a Stream Deck button. I suppose you could modify this macro fairly easily to change the colour of the Stream Deck button depending upon which state the toggle is in.
P.S. You can remove the "Play Tink" action. I was just using that for debugging.