Airplay to Apple TV Automatically when Connected to Wifi and Charging

I am trying to automatically connect to an AppleTV and extend my MacBook Pro screen onto the Apple TV when connected to Wifi and after I plug in the power.

Attached is my current Macro that works, but I'm sure there is a smoother/more efficient/reliable way of doing it.

Thank you in advance!!!

Extend to Apple TV on Wifi and Plugged In.kmmacros (6.6 KB)

CleanShot 2024-02-26 at 14.19.21