Re: enable Access for assistive devices programmatically
Re: enable Access for assistive devices programmatically
- Subject: Re: enable Access for assistive devices programmatically
- From: Bill Cheeseman <email@hidden>
- Date: Fri, 12 Feb 2010 07:01:06 -0500
On Feb 12, 2010, at 6:26 AM, Payal Mundhada wrote:
> I want to enable Access for assistive devices in System Preference programmatically.
>
> We can enable this feature using... System Preferences> Universal Access panel>enable Access for assistive devices.
>
> I am not getting way how to do it via program. Is there any way to do the same?
>
> It will be very helpful if you can suggest me any way.
The OP's inquiry was sent to the carbon-dev list, but I suggested that we discuss it here.
I believe this works on Mac OS X 10.4 Tiger and newer.
You need to use the AXMakeProcessTrusted() function, which is declared in the AXUIElement.h header in the HIServices subframework of the ApplicationServices framework. The header file comments that the process in which you call AXMakeProcessTrusted() must be running as root. What the comments don't say is that you must also quit and relaunch the main application after the user has made it trusted.
I do this as follows: My main application does NOT run as root. In the application package, I include two very small executables. The first executable runs as root; after obtaining user authentication, it runs AXMakeProcessTrusted() to make the main application process trusted. The second executable terminates the main application process and relaunches it. The main application is now trusted. From now on, it can run all accessibility functions even though "Enable access for assistive devices" is NOT turned on in the Universal Access pane of System Preferences. It remains trusted even after the user quits and relaunches it, so the authentication process described above only has to be done once on a particular computer.
Because of new security requirements in Snow Leopard (or was it Leopard?), the executable that runs as root cannot be based on NSApplication.
The main application can run untrusted as long as you like, but of course it cannot use accessibility functions until the user makes it trusted. You can use any normal user interface item to allow the user to make it trusted. I sometimes present an alert as soon as the application is launched, and I sometimes include a button or checkbox or put a setting in a preferences window so that the user can make it trusted at a later time. You can determine whether the main application is trusted by calling the AXIsProcessTrusted() function; for example, you would do this to set the state of a user interface element or suppress the initial alert when the application is launched.
--
Bill Cheeseman
email@hidden
_______________________________________________
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