Re: Monitoring the current Application
Re: Monitoring the current Application
- Subject: Re: Monitoring the current Application
- From: Bill Cheeseman <email@hidden>
- Date: Thu, 24 Jul 2008 11:11:08 -0400
- Thread-topic: Monitoring the current Application
on 2008-07-24 8:43 AM, Chris Idou at email@hidden wrote:
> I wish to write an application that manipulates the currently active text
> field of whatever the current application is when the text changes. It would
> seem then that I need to use AXObserverCreate to get notifications. However
> this API requires a process ID.
>
> This seems to imply I need to find he pid of all current processes and
> register them all, and somehow get notification when new applications are
> launched, or else I would need to find the currently active application, and
> get notification of when the currently active application changes to register
> for notifications.
>
> Am I on the right track, and if so how do I get notifications for the active
> application, no matter what it might be?
You're on exactly the right track. Even better news: Apple has already
written much of the code for you, in the iChatStatusFromApplication sample
code at <http://developer.apple.com/samplecode/iChatStatusFromApplication/>.
In outline:
When your application launches, use NSWorkspace to get a list of all running
applications (-launchedApplications), and to get the process ID of each of
them. Then use the process ID to register an accessibility API observer for
each of them, to receive an accessibility notification when it becomes the
active application.
Also use NSWorkspace to receive notification whenever another application is
launched. When it is, register an accessibility observer to receive
notification when it becomes active.
Also arrange to unregister observers when their application terminates.
Finally, whenever you receive notification that one of the applications has
become the active application, create an accessibility observer to be
notified when its active UI element (the element with keyboard focus)
changes. When it does, check whether it is a text field, then do your thing.
This sounds complicated, but it isn't.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
www.quecheesoftware.com
PreFab Software - www.prefabsoftware.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Accessibility-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden