electron-util
electron-util copied to clipboard
Reading System Preferences [feature request]
Currently there's openSystemPreferences
, what if there was a readSystemPreferences
or something similar. That way we could see what system preferences were currently set.
Yeah, could be useful, but there's no "one way" to read the system preferences. What preferences specifically do you need?
So, I specifically need to display
-
Accessibility
has been enabled for the app (this might work for Accessibility) -
Full Disk Access
has been enabled for the app -
Files and Folders
hasDocuments
,Downloads
, andDesktop
enabled for the app like the Backup and Sync from Google option below
It's not possible to read these from the System Preferences or defaults
. It used to be possible to read the database of permissions directly, but this is no longer possible: https://apple.stackexchange.com/questions/362865/macos-list-apps-authorized-for-full-disk-access
Here's how we could do this:
- https://github.com/karaggeorge/macos-accessibility-permissions
- We can try reading a certain off-limits file: https://github.com/MacPaw/PermissionsKit/blob/43744ea29edb296e177d5890f9fe50d3f5476d52/PermissionsKit/Private/FullDiskAccess/MPFullDiskAccessAuthorizer.m#L68-L76
- We can check whether those directories are writable.
fs.accessSync(path, fs.constants.W_OK);
.
How do you think this api should look?
readSystemPreferences('Accessibility')
readSystemPreferences('FullDiskAccess')
readSystemPreferences('FilesAndFolders', 'Documents')
readSystemPreferences('FilesAndFolders', 'Downloads')
readSystemPreferences('FilesAndFolders', 'Desktop')
Just throwing ideas out there.
@alex-cory They should be separate methods as they all can't behave exactly the same (some might need to be async, for example).
const {hasPrivacyPermission} = require('electron-util');
console.log(hasPrivacyPermission.fullDiskAccess());
console.log(hasPrivacyPermission.filesAndFoldersDesktop());
I can do my best to help implement this.
@sindresorhus : Can we open Notifications settings from System Preference directly?
const {openSystemPreferences} = require('electron-util');
openSystemPreferences('notifications');

@sindresorhus : Please ignore.. i just tried a sample app and it works.. my bad!