Reputation: 68026
I have an application which resides in menu bar, pretty much like this one
And I'm trying to create a preference pane for it, as described in the apple docs.
That guide shows how to create both prefpane plugin for System Preferences and preference window for standalone application. Yet, in the second case, it seems to be missing something.
So, I have main application class with -(IBAction) displayPreferences:(id)sender;
action called when user clicks 'Preferences...' in the menu.
And I also have controller extending NSPreferencePane
and connected to NSWindow
object in Interface Builder (just likes docs describe).
The question is, how to connect them? I.e.,
-(IBAction) displayPreferences:(id)sender {
// what do we write here to display preferences window?
}
Thank you!
Upvotes: 2
Views: 2173
Reputation: 253
There's a very simple way of opening preferences through apple script. Here you go.
And then, simply do the following apple script to open the main sys preference
NSString *script = @"tell application \"System Preferences\"\n\tset the current pane to pane \"com.apple.preferences\"\n\tactivate\nend tell";
NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:script];
[appleScript executeAndReturnError:nil];
the script object can be modified according to where the user has to be navigated. be it bluetooth settings or wifi settings.
Upvotes: 0
Reputation: 243156
If you want to have System Preferences open to your preference pane, you can create a file URL to your .prefPane
bundle and then send that to -[NSWorkspace openURL:]
. If you want to be really explicit about launching options, you can use -[NSWorkspace openURLs:withAppBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifiers:]
.
Upvotes: 2