10

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?

Chetan
  • 46,743
  • 31
  • 106
  • 145
  • Once you are able to detect that the setting has been turned on, how do you begin using the Assistive Access? Is an app restart required? – ck_ Feb 02 '12 at 20:59
  • Asked that question here, looks like you do need a restart: http://stackoverflow.com/questions/9132845/how-do-i-give-my-app-assistive-access-privileges-once-enable-access-for-assis – ck_ Feb 18 '12 at 01:08

2 Answers2

21

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

pkamb
  • 33,281
  • 23
  • 160
  • 191
4

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.

Community
  • 1
  • 1
zpasternack
  • 17,838
  • 2
  • 63
  • 81
  • You should also read the [AXIsProcessTrusted / AXMakeProcessTrusted](http://www.cocoabuilder.com/archive/cocoa/135734-axisprocesstrusted-axmakeprocesstrusted.html) discussion. You'll learn that you should also check for `AXIsProcessTrusted()`. – 0xced Aug 04 '11 at 11:44
  • 1
    `AXAPIEnabled()` has been deprecated in OS X 10.9 Mavericks – pkamb Nov 08 '13 at 00:36
  • 1
    Yes, for this functionality in 10.9, see [this question](http://stackoverflow.com/questions/17693408/enable-access-for-assistive-devices-programmatically-on-10-9) and its most highly rated answer. – zpasternack Nov 08 '13 at 10:03