I am working on a macOS app that is a background app and so I would like to perform a particular function when a keyboard key is pressed. I read from the apple documentation that addGlobalMonitorForEvents(matching:handler: ) must be used. And also to use this, accessibility must be enabled. I checked for accessibility with AXIsProcessTrustedWithOptions and the functionality has been implemented and it works right. I give an alert to the user asking to enable accessibility and if the user agrees, the accessibility in the privacy system preferences window opens. Now, the issue I face is the app is not present in the accessibility list and so the user has to add the app manually into the list. Is there any way to programmatically(SWIFT) add the app to the accessibility list?
Asked
Active
Viewed 249 times
1 Answers
-1
Hy MaraV932,
this is very easy, only what you should do is to add this:
<key>NSUserInterfaceAccessibility</key>
<dict>
<key>Enabled</key>
<true/>
</dict>
to your <AppName>.entitlements
file then rebuild your project again, it should now open a dialog to go to the settings to give the app accessibility access, the app should now display in the list.

Khalil Khalil
- 491
- 7
- 17
-
didn't work for me https://stackoverflow.com/q/76807911/4423545 – Andrew_STOP_RU_WAR_IN_UA Aug 01 '23 at 02:06
-
@Khalil Khalil: this key does not seem to be documented. Not findable in Apple Documentation or via Google. Can you point to any reference documentation or example? – soundflix Aug 02 '23 at 10:03