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
+2
A:
No brainer:
system("open -a System\\ Preferences");
And to choose a Pane to open:
open /System/Library/PreferencePanes/Internet.prefPane
open /System/Library/PreferencePanes/DateAndTime.prefPane
...
Find the right file in /System/Library/PreferencePanes/
and open
it.
I'm sure there's a more cocoa way to do it, still... works with every language.
ZJR
2009-11-18 00:56:42
Sidenote: you may want also to check `~/Library/PreferencePanes/` and `/Library/PreferencePanes` that's where **third parties** install their panes.
ZJR
2009-11-18 01:05:48
A:
How exactly did you use the Scripting Bridge?
I tried with this code and I think it performs reasonably well:
SystemPreferencesApplication *SystemPreferences = [SBApplication applicationWithBundleIdentifier:@"com.apple.systempreferences"];
@try {
[SystemPreferences activate];
SystemPreferences.currentPane = [SystemPreferences.panes objectWithID:@"com.apple.preference.security"];
} @catch (NSException *exception) {
NSLog(@"%@", [exception description]);
}
Here is another option just for fun which is Cocoa, but not documented at all (and only works with system preference panes). You may use it to compare performances, but don't use it in production code.
id bezelServicesTask = [NSConnection rootProxyForConnectionWithRegisteredName:@"com.apple.BezelServices" host:nil];
[bezelServicesTask performSelector:@selector(launchSystemPreferences:) withObject:@"Security.prefPane"];
0xced
2009-11-18 09:48:32
I have the exact same Scripting Bridge code as you (well, minus the exception code) - I took mine from the Apple sample. The weird thing is that if I double-click on the prefpane file already inside the PreferencePanes folder, System Preferences opens and loads the pane instantly.
K_T
2009-11-18 22:29:02
+1
A:
Use Launch Services or NSWorkspace to open the prefpane bundle. That's the programmatic version of the open(1) command.
Peter Hosey
2009-11-18 10:13:00
Indeed: `[[NSWorkspace sharedWorkspace] openFile:@"/Path/To/Foo.prefPane"];`
Max Howell
2009-11-18 20:20:40
I'm not usually keen on this though as you have to figure out where your Third Party prefpane has been installed. Alas, using bundle identifiers with the appropriate NSWorkspace call doesn't seem to work.
Max Howell
2009-11-18 20:21:33
There are only two places it could be, and you can use `NSSearchPathForDirectoriesInDomains` to look in both of them.
Peter Hosey
2009-11-18 20:31:39