5

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?

Jinja_dude
  • 404
  • 5
  • 20
MaraV932
  • 51
  • 1

1 Answers1

-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