Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

269
Views
How to prompt for accessibility features in a macOS app (from the AppDelegate)?

I'm building a macOS application that requires monitoring global keystrokes. So the global event listener would be:

NSEvent.addGlobalMonitorForEvents(matching: NSEvent.EventTypeMask.keyDown) { (event) in
          print(event.keyCode)
}

But this does nothing as mentioned in this thread. I did try the answer given in the thread by adding:

let options: NSDictionary = [kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String : true]
let accessEnabled = AXIsProcessTrustedWithOptions(options)
      

if !accessEnabled {
   print("Access Not Enabled")
} else {
   print("Access Granted")
}

This prompts the dialog box to request access but since it's an asynchronous process, giving access is still not moving the thread to a point where I can monitor keystrokes. Besides, this dialog box pops up on each launch of the app, how to curate this graceful requesting of accessibility without the hassle, as there's no proper documentation anywhere, as far as I searched.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I realized this is an Xcode bug instead. This is caused if the SwiftUI preview provider is run concurrently with the actual build, this causes some confusion with the accessibility permissions with macOS.

The application works as expected after the derived data directory is cleaned. You can do that with

rm -rf ~/Library/Developer/Xcode/DerivedData
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!