How to get a notification about opening a new window?

I want to answer a certain type of new window opened by an external application. I have some experience finding applications and windows that are currently open (in the system) using some carbon functions, so theoretically you could just check every few seconds. This will require getting a list of all open windows and checking it for some list that I will need to maintain, and it feels very awkward.

How can I get a simple, clean notification when I start a new window? Should I use the accessibility API? If so, what exactly am I looking for?

+3
source share
1 answer

First create an AXObserver. Then follow the launches of any applications that you think you are interested in. When such a launch occurs, create the AXUIElement application for this process and add an observer to it for notification kAXWindowCreatedNotification.

I doubt this is the best way to do what you are trying to do. You can step back a bit from this decision (that is, watch for new windows) and ask another question about your purpose.

+1
source

Source: https://habr.com/ru/post/1733791/


All Articles