首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >以编程方式打开Privacy>Accessibility窗口

以编程方式打开Privacy>Accessibility窗口
EN

Stack Overflow用户
提问于 2015-01-09 08:18:40
回答 5查看 2.1K关注 0票数 7

我正在开发这个应用程序,它需要从系统首选项>安全性和隐私>隐私>可访问性来启用。

现在,我正在使用以下代码打开屏幕截图中所示的窗口:

代码语言:javascript
运行
复制
-(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];
}

但没有必要打开“可访问性”选项卡。相反,它打开以前打开的选项卡。

因此,请建议我修改这段代码的方法,它将在此窗口的侧菜单中专门打开“可访问性”选项卡。

提前谢谢。

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2018-08-16 23:26:03

https://macosxautomation.com/system-prefs-links.html有一页链接到许多(但不是全部)各种偏好窗格。经过一点猜测,我能够验证这些调用在macOS Mojave beta 7下是否有效。当用户拒绝访问应用程序无法运行的设备时,我使用这些调用引导用户找到正确的窗格。

代码语言:javascript
运行
复制
// 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"]];
票数 8
EN

Stack Overflow用户

发布于 2015-01-12 04:48:39

在搜索解决方案时,我发现从对我有用的this question中的一些提示中生成了以下代码。

这就是我想要实现的。

谢谢你支持你的评论。

代码语言:javascript
运行
复制
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
EN

Stack Overflow用户

发布于 2018-12-05 21:20:29

Swift 4兼容版本,从已接受的答案中采用:

代码语言:javascript
运行
复制
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)
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27856351

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档