在Mac应用程序中运行AppleScript时“不允许辅助访问”错误

时间:2017-03-18 09:04:46

标签: macos applescript authorization nsapplescript

我的代码是

NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource:
                               @"\
                               tell application \"System Preferences\"\n\
                               set current pane to pane id \"com.apple.preference.energysaver\"\n\
                               end tell\n\
                               tell application \"System Events\"\n\
                               tell process \"System Preferences\"\n\
                               tell window 1\n\
                               tell group 1 -- automatic graphics switching\n\
                               tell checkbox 1 -- automatic graphics switching\n\
                               click\n\
                               end tell\n\
                               end tell\n\
                               end tell\n\
                               end tell\n\
                               end tell"];

returnDescriptor = [scriptObject executeAndReturnError: &errorDict];

它打算自动更改图形,当我尝试它时,我有错误

  

系统事件出错:辅助访问不允许使用“mactest”

我确定代码是正确的,它在AppleScript编辑器中运行良好,如果删除"单击\ n \"也可以正常运行线。 我已经将我的应用程序以及AppleScript编辑器添加到Security&隐私,但仍无用。

1 个答案:

答案 0 :(得分:0)

我相信我也遇到过这个问题。我想制作一个小型AppleScript来关注并最大化StepMania。我将其导出为应用程序,因此我可以将其添加到登录项目中。在我给出AppleScript Editor可访问性权限后添加最大化功能。

System Preferences -> Security & Privacy -> Privacy -> Accessibility -> AppleScript Editor

但是,在将其作为应用程序导出后,它现在没有通过AppleScript编辑器运行,并且没有所需的辅助功能权限。

AppleScript app is not allowed assistive access

您需要提供应用程序辅助功能权限。

AppleScript app would like to control this computer using accessibility features

这样的对话可能会导致您将应用拖到列表中。