2

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!

Nikita Rybak
  • 67,365
  • 22
  • 157
  • 181

2 Answers2

2

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

Dave DeLong
  • 242,470
  • 58
  • 448
  • 498
  • That's quite opposite, actually. [Apple says](http://developer.apple.com/library/mac/#documentation/UserExperience/Conceptual/PreferencePanes/Concepts/Application.html#//apple_ref/doc/uid/20000702-CJBJFACH) that I can reuse PreferencePanes framework in my application, without adding anything to System Preferences. Is that correct? (see 'Target Application' chapter in the link) Or should I just create new window and not bother with PreferencePanes framework? – Nikita Rybak Feb 02 '11 at 21:46
  • @Nikita Yes that's correct. The documentation (along with example code) on that is [here](http://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/PreferencePanes/Tasks/OtherApps.html#//apple_ref/doc/uid/20000711-BBCBAGAH). – Dave DeLong Feb 02 '11 at 21:48
  • Thanks, I must've missed item 1 there when reading before. I'll try it and see what happens! (gotta read about bundles too :/) – Nikita Rybak Feb 02 '11 at 21:53
  • In particular, you should pass the “don't add to recents” option to the latter method. The user will not appreciate your prefpane showing up among their Recent Documents. – Peter Hosey Feb 03 '11 at 17:06
0

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.

user6502515
  • 143
  • 11