【问题标题】:How do I open the "Share Menu" preferences on OSX?如何在 OSX 上打开“共享菜单”首选项?
【发布时间】:2018-09-19 16:01:50
【问题描述】:

很像 Safari,尝试实现一个按钮,单击该按钮会打开“系统偏好设置”>“扩展”>“共享菜单”窗格。

我试过了:

NSURL *URL = [NSURL URLWithString:@"x-apple.systempreferences:com.apple.preferences.extensions?Share_Menu"];
[[NSWorkspace sharedWorkspace] openURL:URL];

但是,这似乎不适用于较新的版本,有什么想法吗?

【问题讨论】:

    标签: macos cocoa


    【解决方案1】:

    您可以使用 Scripting Bridge 执行以下操作:

     SBSystemPreferencesApplication *systemPrefs =
    [SBApplication applicationWithBundleIdentifier:@"com.apple.systempreferences"];
    
    [systemPrefs activate];
    
    SBElementArray *panes = [systemPrefs panes];
    SBSystemPreferencesPane *notificationsPane = nil;
    
    for (SBSystemPreferencesPane *pane in panes) {
        if ([[pane id] isEqualToString:@"com.apple.preferences.extensions"]) {
            notificationsPane = pane;
            break;
        }
    
    }
    
    [systemPrefs setCurrentPane:notificationsPane];
    
    SBElementArray *anchors = [notificationsPane anchors];
    
    for (SBSystemPreferencesAnchor *anchor in anchors) {
        if ([anchor.name isEqualToString:@"Extensions"]) {
            [anchor reveal];
        }
    }
    

    当然,您需要将 ScriptingBridge 框架添加到您的项目中,并为系统偏好添加一个 Scripting Bridge 头文件。有关如何使用 Scripting Bridge 的更多详细信息,您可以在 Apple 的开发人员文档中找到。

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多