Engineering Blog

Request Accessibility Control for a MacOS App

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()`
}
Gertrude

The Gertrude mac app helps you protect your kids online with strict internet filtering that you can manage from your own computer or phone, plus remote monitoring of screenshots and keylogging. $5/mo, with a 60 day free trial.

Start free trial →