views:

145

answers:

1

I'm trying to automate a foreign OSX application using the accessibility API. Some of the state of the application isn't available through the API, so I acquire it through screen scraping. To do this, I need to get CGWindowID for an accessibility object with a 'Window Role'.

Is there any direct way of acquiring CGWindowID of a 'Window Role' accessibility object? I can get it heuristically, by matching various attributes of the window, such as the size, title and location, but this is really hacky, and I'd feel better if my application would also support the corner cases, even if they are unlikely.

+2  A: 

There’s no way to do that; the accessibility hierarchy is completely decoupled from the actual window/view hierarchy. I think your matching will work best.

Ben Stiglitz
Thanks for the answer. I already suspected that, but just nice to have someone else confirm it. Anyway, I have my matching logic working good enough for my purposes through position and size matching, as well as some additional logic used to move windows a pixel left/right/up/down in case on conflicts.
Sami