I'm working on a macOS app that needs to manipulate the windows of other applications, namely bringing another app's window to the front. Note that it's not enough to simply bring an application to the front (which is easily accomplished with NSRunningApplication
) -- it needs to be a specific window.
Normally I would use the Accessibility API to do this, but unfortunately it's not reliable. Some applications do not respond to API requests in a timely manner or will return bogus or broken information, which can break my app. Consequently, I'm looking for alternative methods of doing this.
I'm open to using unofficial macOS APIs, which, while I know they are not recommended, I've found can often be a lot faster and more reliable. For example, I needed a method to figure out which window occupied a certain point on screen. While it is possible and supported to do this with the Accessibility API, it would often be very slow, or just break completely with apps that don't support Accessibility features correctly. But using the undocumented function CGSFindWindowAndOwner
is much faster and more reliable, as it just queries the window server directly. I'm hoping I can find a similar method for raising a window too.
That said, if there is another supported method I'll certainly go for that, but I'm not aware of any other way of doing this without resorting to unofficial / undocumented APIs. (Maybe Apple Events can do it?)
Do I have any options other than trying to work around the bugs and failings of the Accessibility API?