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

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

问题描述:

我的代码是在Mac应用程序运行的AppleScript时,“不允许辅助访问”错误

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]; 

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

System Events got an error:“mactest”is not allowed for assistive access

我确定代码是正确的,它在AppleScript编辑器中运行良好,并且在删除“click \ n \”行时也可以正常运行。 我已经将我的应用以及AppleScript编辑器添加到安全&隐私中,但仍然无用。

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

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

一些像这样的对话可能会导致你拖动您的应用程序列表。