单击Apple脚本"始终允许"协同设置访问不起作用

时间:2017-01-08 08:10:01

标签: ios xcode applescript keychain

我试图使用苹果脚本自动点击"始终允许"从命令行构建ios app时,在协同对话中按钮。但脚本似乎抛出错误。我不是处理苹果脚本的专家。这是脚本

tell application "System Events"
    if (exists process "SecurityAgent") then
        tell window 1 of process "SecurityAgent"
            click button "Always Allow" of group 1
        end tell
    end if
end tell

并且运行时出现的错误是

error "System Events got an error: Can’t get group 1 of window 1 of process \"SecurityAgent\". Invalid index." number -1719 from group 1 of window 1 of process "SecurityAgent"

enter image description here

任何帮助将不胜感激 谢谢。

1 个答案:

答案 0 :(得分:0)

似乎您必须首先聚焦窗口。由于某种原因,可访问性引擎不认为它不存在。

#!/usr/bin/osascript

tell application "System Events"
    if (exists process "SecurityAgent") then
        tell process "SecurityAgent"
            activate
            set frontmost to true
        end tell
        tell window 1 of process "SecurityAgent"
            click button "Always Allow"
        end tell
    end if
end tell