Programmatically determine whether "enable access for assistive devices" is allowed in a Cocoa application

Applications

Cocoa, using the NSAccessibility API, requires that the Allow access to assistive devices check box is selected in the Universal Access access panel. I saw that many applications raise a warning if it is disabled when they start. How to programmatically check if this is enabled so that I can show a warning in my application?

+6
source share
2 answers

I think you are looking for AXAPIEnabled() .

 extern Boolean AXAPIEnabled (); 

Quote docs :

Returns whether the accessibility API is enabled.

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

Supporting applications will not work if the accessibility API or if the calling process is not a reliable accessibility client. Users can enable the accessibility API by checking the "Enable access for assistive devices" checkbox in the accessibility settings.

+4
source

On OS X 10.9 Mavericks, AXAPIEnabled() deprecated .

AXIsProcessTrustedWithOptions can be used instead:

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

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

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

enter image description here

+11
source

Source: https://habr.com/ru/post/894231/


All Articles