我正在开发这个应用程序,它需要从系统首选项>安全性和隐私>隐私>可访问性来启用。
现在,我正在使用以下代码打开屏幕截图中所示的窗口:
-(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];
}
但没有必要打开“可访问性”选项卡。相反,它打开以前打开的选项卡。
因此,请建议我修改这段代码的方法,它将在此窗口的侧菜单中专门打开“可访问性”选项卡。
提前谢谢。
发布于 2018-08-16 23:26:03
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"]];
发布于 2015-01-12 04:48:39
在搜索解决方案时,我发现从对我有用的this question中的一些提示中生成了以下代码。
这就是我想要实现的。
谢谢你支持你的评论。
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];
}
发布于 2018-12-05 21:20:29
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)
}
https://stackoverflow.com/questions/27856351
复制相似问题