Activate SideCar to Enable iPad as a Second Monitor

I've had some time to test this now. I had two problems:

  1. The menu would not be clicked for some reason (race condition)?
  2. The macro would execute twice if triggered by the usb attached condition.

I think I managed to solve both of the issues.
My apple script now looks like this (using Swedish window names etc):

I also added a semaphore to help with the multiple triggers problem. I hope this can help someone else running into these issues.