Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically determine if "enable access for assistive devices" is checked in Cocoa app

Cocoa apps using the NSAccessibility API require "enable access for assistive devices" to be checked in the Universal Access pref pane. I've seen many apps pop a warning if this is disabled when they run. How do I programmatically check if this is enabled so I can show a warning in my app?

like image 494
Chetan Avatar asked Aug 03 '11 21:08

Chetan


2 Answers

In OS X 10.9 Mavericks, AXAPIEnabled() has been deprecated.

AXIsProcessTrustedWithOptions can be used instead:

NSDictionary *options = @{(id)kAXTrustedCheckOptionPrompt: @YES};
BOOL accessibilityEnabled = AXIsProcessTrustedWithOptions((CFDictionaryRef)options);

If you pass in YES for kAXTrustedCheckOptionPrompt, the system will show the user a helpful little dialog with a link to System Preferences:

"YourApp.app would like to control this computer using accessibility features."

enter image description here

like image 56
pkamb Avatar answered Nov 12 '22 01:11

pkamb


I think you're looking for AXAPIEnabled().

extern Boolean AXAPIEnabled ();  

Quoting the docs:

Returns whether the accessibility API is enabled.

Returns TRUE if the accessibility API is currently enabled, otherwise FALSE.

Assistive applications will not work if the accessibility API is not enabled or if the calling process is not a trusted accessibility client. Users can enable the accessibility API by checking "Enable access for assistive devices" in Universal Access Preferences.

like image 4
zpasternack Avatar answered Nov 12 '22 00:11

zpasternack