Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ask for Accessibility permission in macOS

Tags:

macos

The below code doesn't work since Mojave without Accessibility permission

KeyMap keyStatesBig; GetKeys(keyStatesBig);

But is there a key to put in info.plist to ask users permission on app launch?

like image 652
Steve Dremelzen Avatar asked Dec 04 '18 15:12

Steve Dremelzen


People also ask

How do you enable Accessibility permission on a Mac?

If you later decide to give a denied app access to your Mac, choose Apple menu > System Preferences, click Security & Privacy , click Privacy, click Accessibility, then select the app's checkbox.

How do you request access on a Mac?

To change application permissions on a mac, click the Apple icon → Click "System Preferences" → Click "Security & Privacy" → Click "Privacy" → Click on a service → Click the check box to add or remove an app's permission to the selected service.


Video Answer


1 Answers

It's not possible with the info.plist.

You can ask the user yourself, on startup. Use AXIsProcessTrusted to determine whether accessibility is enabled or not.

If it's not enabled, you can show a dialog asking the user to switch it on.

You can open the relevant preferences for the user also:

NSString* prefPage = @"x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility";
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:prefPage]];

See how Dropbox does it (this is custom UI):

enter image description here

(The Turn on Accessibility button simply opens the System Preferences to the correct place, as mentioned above)

like image 128
TheNextman Avatar answered Sep 22 '22 21:09

TheNextman