我正在处理需要从系统偏好设置启用的应用>安全和隐私>隐私>可访问性。
现在,我使用以下代码打开下面屏幕截图中显示的窗口:
-(IBAction)enableAccessibility
{
NSString *script = @"tell application \"System Preferences\" \n reveal anchor \"Privacy\" of pane id \"com.apple.preference.security\" \n activate \n end tell";
NSAppleScript *scriptObject = [[NSAppleScript alloc] initWithSource:script];
[scriptObject executeAndReturnError:nil];
}
但没必要打开“辅助功能”标签。相反,它打开以前打开的选项卡。
所以请建议我修改此代码的方法,该代码将从此窗口的侧面菜单中专门打开“辅助功能”选项卡。
提前致谢。
答案 0 :(得分:5)
https://macosxautomation.com/system-prefs-links.html的页面链接指向许多(但不是全部)各种首选项窗格。通过一些猜测,我能够验证这些调用在macOS Mojave beta 7下是否有效。当他们拒绝访问该应用程序可以访问的设备时,我正在使用这些调用将用户引导至正确的窗格。不用。
// open last Privacy subpane viewed:
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"x-apple.systempreferences:com.apple.preference.security?Privacy"]];
// specify a particular subpange
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"x-apple.systempreferences:com.apple.preference.security?Privacy_Camera"]];
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone"]];
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"x-apple.systempreferences:com.apple.preference.security?Privacy_Automation"]];
答案 1 :(得分:2)
在搜索解决方案时,我发现this question中的一些提示生成了以下代码,这对我有用。
这就是我想要实现的目标。
感谢@duskwuff支持你的评论。
NSString *script;
if ([[[[NSProcessInfo processInfo] operatingSystemVersionString] substringToIndex:12] isEqualToString:@"Version 10.7"] || [[[[NSProcessInfo processInfo] operatingSystemVersionString] substringToIndex:12] isEqualToString:@"Version 10.8"])
{ //>> For OSX 10.7 and 10.8
script = @"tell application \"System Preferences\" \n set the current pane to pane id \"com.apple.preference.universalaccess\" \n activate \n end tell";
NSAppleScript *scriptObject = [[NSAppleScript alloc] initWithSource:script];
[scriptObject executeAndReturnError:nil];
}
else
{ //>> For OSX 10.9 and 10.10
script = @"tell application \"System Preferences\" \n reveal anchor \"Privacy_Accessibility\" of pane id \"com.apple.preference.security\" \n activate \n end tell";
NSAppleScript *scriptObject = [[NSAppleScript alloc] initWithSource:script];
[scriptObject executeAndReturnError:nil];
}
答案 2 :(得分:1)
与Swift 4兼容的版本,从接受的答案中采用:
static func openAccessibilityPreferences() {
let macOS10version = ProcessInfo.processInfo.operatingSystemVersion.minorVersion
let script = macOS10version < 9
? "tell application \"System Preferences\" \n set the current pane to pane id \"com.apple.preference.universalaccess\" \n activate \n end tell"
: "tell application \"System Preferences\" \n reveal anchor \"Privacy_Accessibility\" of pane id \"com.apple.preference.security\" \n activate \n end tell"
NSAppleScript(source: script)?.executeAndReturnError(nil)
}
答案 3 :(得分:0)
找到更简单的解决方案:
NSURL *URL = [NSURL URLWithString:@"x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility"];
[[NSWorkspace sharedWorkspace] openURL:URL];
如果您只需要打开prefPane
NSURL *URL = [NSURL URLWithString:@"/System/Library/PreferencePanes/Security.prefPane"];
[[NSWorkspace sharedWorkspace] openFile:[URL relativePath]];
答案 4 :(得分:0)
使用shell命令的一种方法是
/bin/sh -c open -b com.apple.systempreferences /System/Library/PreferencePanes/Security.prefPane
如果您知道如何从命令行打开它,则可以自定义编程方式