adding preference pane to an application

2.1k views Asked by At

I have an application which resides in menu bar, pretty much like this one
menu app

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!

2

There are 2 answers

4
Dave DeLong On BEST ANSWER

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:].

0
user6502515 On

There's a very simple way of opening preferences through apple script. Here you go.

  1. You gotta create a button action and set the outlet of prefernces to the button action
  2. 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.