home ~ projects ~ socials

Open The macOS Accessibility System Preference Dialog Box Automatically From A SwiftUI App

Update: APP_NAME/APP_NAME/APP_NAME.entitlements

Change: App Sandbox to NO

Then add this code to check the permissions and open the dialog box if you don't have permissions:

func checkPermissions() -> Bool {
    let options : NSDictionary = [kAXTrustedCheckOptionPrompt.takeRetainedValue() as NSString: true]
    return AXIsProcessTrustedWithOptions(options)
}

Then call checkPermissions() when you need.

-- end of line --

Endnotes

  • I was doing some looking through entitlements for the accessibility, but that's not where they are. It's the AXIsProcessTrustedWithOptions call that does the work. But, you have to turn off the App Sandbox in entitlements to get the dialog (which is called "Accessibility Access") to show up directly.

  • For reference and to aid search, the full text of the dialog is "APP_NAME" would like to control this computer using accessibility features. Grant access to this application in Privacy & Security settings, located in System Settings

    Then there are two buttons for "Open System Settings" and "Deny"

References