If you need your app to have access to global events (like keystrokes) which require that the app is granted authorization to control your computer in the Security and Privacy pane of system extensions, you can prompt the user for this privilege with the below code:
let prompt = kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String let options: NSDictionary = [prompt: true] let appHasPermission = AXIsProcessTrustedWithOptions(options) if appHasPermission { // do something with permission, like `NSEvent.addGlobalMonitorForEvents()` }