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

2

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?

Croatian answered 3/8, 2011 at 21:26 Comment(2)
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?Southwestward
Asked that question here, looks like you do need a restart: #9133345Southwestward
L
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.

Lendlease answered 3/8, 2011 at 22:30 Comment(3)
You should also read the AXIsProcessTrusted / AXMakeProcessTrusted discussion. You'll learn that you should also check for AXIsProcessTrusted().Ennead
AXAPIEnabled() has been deprecated in OS X 10.9 MavericksHalfbaked
Yes, for this functionality in 10.9, see this question and its most highly rated answer.Lendlease
H
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

Halfbaked answered 26/10, 2013 at 20:59 Comment(0)
L
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.

Lendlease answered 3/8, 2011 at 22:30 Comment(3)
You should also read the AXIsProcessTrusted / AXMakeProcessTrusted discussion. You'll learn that you should also check for AXIsProcessTrusted().Ennead
AXAPIEnabled() has been deprecated in OS X 10.9 MavericksHalfbaked
Yes, for this functionality in 10.9, see this question and its most highly rated answer.Lendlease

© 2022 - 2024 — McMap. All rights reserved.