Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

265
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda