macoselectronsystem-preferences

How to read mac system preferences programmatically?


I'm trying to tell if a user has specific system preferences set. I.e. the app needs to know if they've given Full Disk Access, if they've selected our app under Accessibility, etc. like in the picture below.

I know we can do something like

defaults read com.apple.AppleMultitouchTrackpad

but I'm having trouble finding this out for Full Disk Access, Files and Folders, and Accessibility under Security & Privacy.

Is there a list of the com.apple.XXX somewhere?

I'm basically trying to do something like

defaults read com.apple.security.Privacy_Accessibility

I'm able to open the system preferences pane with electron like

shell.openExternal('x-apple.systempreferences:com.apple.preference.security.Privacy_Accessibility')

So I thought there might be a way similar to this for reading the settings.

enter image description here


Solution

  • To determine if accessibility access is enabled, you can use AXIsProcessTrusted and it's counterpart, AXIsProcessTrustedWithOptions. Both are part of ApplicationServices. From the documentation:

    Returns TRUE if the current process is a trusted accessibility client, FALSE if it is not.

    It doesn't seem possible to detect if FDA is enabled or not; there is no API for that. Some developers try to test access by attempting to read a known protected file and seeing if that works or not; but this approach is fragile and Apple does recommend against it. More discussion here.