以编程方式启动Mac的系统首选项屏幕 - >声音

时间:2013-06-14 20:58:48

标签: macos cocoa operating-system

是否有一种以编程方式在Mac上启动系统设置并将其重点放在声音窗格上?

如果是这样,是否有一种编程方式将其默认设置在“输出”选项卡上?

3 个答案:

答案 0 :(得分:10)

有一种更简单的方法:

NSURL * url = [NSURL fileURLWithPath:@"/System/Library/PreferencePanes/Speech.prefPane"];
[[NSWorkspace sharedWorkspace] openURL:url];

答案 1 :(得分:5)

你可以申请它:

tell application "System Preferences"
    activate
    set the current pane to pane id "com.apple.preference.sound"
    reveal anchor "Output" of pane id "com.apple.preference.sound"
end tell

改编自this link

答案 2 :(得分:0)

我有一个类似的问题:
我想在“安全性和隐私”系统偏好设置面板中打开“隐私”标签。

您可以使用以下命令在终端上实现此目标:

open x-apple.systempreferences:com.apple.preference.security?Privacy

因此,我在我的应用程序中尝试了以下操作,该操作无效:

// does not work!!!
[[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath:@"x-apple.systempreferences:com.apple.preference.security?Privacy"]];

所以我实现了这种hacky解决方案:

NSTask *task = [[NSTask alloc] init];
task.launchPath = @"/bin/sh";
task.arguments = @[@"-c" , @"open x-apple.systempreferences:com.apple.preference.security?Privacy"];
[task launch];

在macOS 10.14.6上进行了测试。