Connect and disconnect to Apple TV

Is there a reliable way I can create an action to connect to my Apple TV and also to disconnect?
I was able to make an action that uses a click, then left arrow and down arrow then return to select my AppleTV. It works, but then my screen resolution changes, and the mouse target doesn't work anymore, due to the new pixel target.
Is there a better way to go about this?

I think you mean connect a macOS computer to Apple TV via the Airplay icon's pull down list in the Menu Bar.

Sure we can get that to work. But there are probably different ways to solve this. If you show us your macro, we can probably modify your macro to make it work reliably. If we show you our own ways, that might be totally different from your approach. Nothing wrong with a different approach, especially if it's more reliable, but it's probably more educational for you if we fix your approach than give you a whole new approach.

Or if you just want to jump to the right way, let us know. However I'm not sure I know the most right way to solve this.

Yes, I’m talking about using a keystroke to have my MacBook connect to my Apple TV.
What’s the most reliable way? I tried using the mouse click but as the computer changes resolution after connecting, I can’t use it reliably to aim the mouse for clicking.
Anyone know a better way?