Re: Access main window of other Applications
Re: Access main window of other Applications
- Subject: Re: Access main window of other Applications
- From: Bill Cheeseman <email@hidden>
- Date: Fri, 08 Apr 2011 06:13:43 -0400
On Apr 7, 2011, at 11:01 AM, Florian Pilz wrote:
> c) I couldn't find any examples on using the NSAccessibility
> protocol to retrieve the main window, not mentioning the discomfort
> that the user may activate access to accessibility features first.
The NSAccessibility protocol is intended for use by applications that want to make themselves accessible, so that is not what you want.
To write a so-called "assistive application" that can access the UI elements of another application, use the Accessibility API. It is documented in the "Accessibility (ApplicationServices/ā€¨HIServices) Reference"document, and also look for documentation listed in "Accessibility Overview." There are two sample code packages available from Apple, only one of which I remember: UIElementInspector. This is a C API, not Objective-C, but once you've studied the sample code you'll see that it is relatively easy to adapt to it and to incorporate it into a Cocoa application.
The Accessibility API does normally require the user to turn on the "Enable Access for Assistive Devices" setting in the Universal Access pane of System Preferences. Apple requires this in order to force the user to authenticate for security reasons, and that's just the way it is. Most developers test whether accessibility is enabled (using one of the Accessibility API functions for that purpose), and then if necessary include in their applications a dialog that tells the user to turn it on and open the Universal Access pane for them.
In my applications, I put up an authentication dialog myself and, after the user enters name and password, make my application "trusted" by the Accessibility API so that it is not necessary to turn on the global setting. This is more convenient for the user, but it is very complicated to code because it requires one or two small helper applications embedded in your application package, one of which must (very briefly) run as root. Also, if you use this "trusted" feature of the Accessibility API, your application will not be eligible for the Mac App Store.
--
Bill Cheeseman - email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden