添加偏好设置面板应用

添加偏好设置面板应用

问题描述:

我有它驻留在菜单栏上的应用程序,非常喜欢这个
menu app添加偏好设置面板应用

而且我想创建偏好窗格吧,在the apple docs描述。
该指南演示了如何为系统偏好设置和独立应用程序的首选项窗口创建预发送插件。然而,在第二种情况下,它似乎缺少了一些东西。

所以,我有主要的应用程序类与-(IBAction) displayPreferences:(id)sender;行动调用当用户点击菜单中的“首选项...”。
而且我也有控制器扩展NSPreferencePane并连接到Interface Builder中的NSWindow对象(就像文档描述一样)。

问题是,如何连接它们?即,

-(IBAction) displayPreferences:(id)sender { 
    // what do we write here to display preferences window? 
} 

谢谢!

如果您希望系统偏好设置对您的偏好设置窗格打开,您可以创建一个文件URL到您的.prefPane包,然后将其发送到-[NSWorkspace openURL:]。如果你想明确启动选项,你可以使用-[NSWorkspace openURLs:withAppBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifiers:]

+0

实际上,情况恰恰相反。 [Apple说](我可以重复使用)(http://developer.apple.com/library/mac/#documentation/UserExperience/Conceptual/PreferencePanes/Concepts/Application.html#//apple_ref/doc/uid/20000702-CJBJFACH)我的应用程序中的PreferencePanes框架,而不向系统偏好设置添加任何内容。那是对的吗? (请参阅链接中的“目标应用程序”一章)还是应该创建新窗口而不用PreferencePanes框架? – 2011-02-02 21:46:21

有一个非常简单的通过苹果脚本打开偏好的方法。干得好。

  1. 你必须创建一个按钮动作并设置prefernces出口到按钮动作
  2. 然后,根本看下面的Apple脚本打开主SYS偏好

    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]; 
    

脚本对象可以根据用户必须导航的位置进行修改。无论是蓝牙设置或WiFi设置。