AppleScript was too slow, so I tried ScriptingBridge to open System Preferences.app and set the current pane, which is also too slow. Is there a faster way to do it? properly
A more direct method than using the file system path is to use the appropriate resource URL for the preference pane with NSWorkspace as shown:
NSString *urlString = @"x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility";
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:urlString]];
where the urlString
was taken from a list of some of the possible URL strings https://macosxautomation.com/system-prefs-links.html
Use Launch Services or NSWorkspace to open the prefpane bundle. That's the programmatic version of the open(1) command.
No brainer:
system("open -a System\\ Preferences");
And to choose which Pane to open:
open /System/Library/PreferencePanes/Internet.prefPane
open /System/Library/PreferencePanes/DateAndTime.prefPane
...
Provided you found, with a little trial and error, the right file in /System/Library/PreferencePanes/
first.
I'm sure there's a more cocoa way to do this last trick, still... this one works with every language.
Also: you may want to check these paths
/Library/PreferencePanes/ ~/Library/PreferencePanes/
...as that's where third party apps install their
*.prefPane
files
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With