2011-02-02 59 views
2

我有它駐留在菜單欄上的應用程序,非常喜歡這個
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? 
} 

謝謝!

回答

2

如果您希望系統偏好設置對您的偏好設置窗格打開,您可以創建一個文件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

0

有一個非常簡單的通過蘋果腳本打開偏好的方法。幹得好。

  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設置。