Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest way to programmatically open prefpane?

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

like image 640
K_T Avatar asked Nov 18 '09 00:11

K_T


3 Answers

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

like image 130
notedible Avatar answered Nov 20 '22 18:11

notedible


Use Launch Services or NSWorkspace to open the prefpane bundle. That's the programmatic version of the open(1) command.

like image 45
Peter Hosey Avatar answered Nov 20 '22 18:11

Peter Hosey


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

like image 5
ZJR Avatar answered Nov 20 '22 20:11

ZJR