如何点击弹出的对话框窗口

3
我在编写自动运行DiskWarrior的代码时遇到了问题。问题是当我打开应用程序时,会弹出一个SecurityAgent对话框,要求输入用户名和密码,但我不知道如何“点击”进入Security Agent窗口以便输入用户名和密码。我知道如何编写用户名/密码,但不知道如何“点击”进入SecurityAgent窗口。我尝试使用UI检查器,但迄今为止没有成功。有人知道如何编写“点击”SecurityAgent窗口的代码吗?
非常感谢任何帮助和反馈。
以下是我目前的代码,仍在努力解决问题:
tell application "DiskWarrior"
    open
end tell
delay 1
tell application "System Events"
    tell process "SecurityAgent"
        click text field 1
        delay 3
        keystroke "a user name"
                delay 3
                keystroke tab
                delay 3
                keystroke "a password"
                delay 3
                keystroke return
    end tell
end tell
2个回答

2
你可以使用 set frontmost to trueactivate application "SecurityAgent" 命令将其置于焦点。
tell application "System Events" to tell process "SecurityAgent"
    set frontmost to true
end

您还可以使用UI脚本来设置密码字段的值并点击“确定”按钮:

tell application "System Events" to tell process "SecurityAgent"
    set value of text field 2 of scroll area 1 of group 1 of window 1 to "password"
    click button 2 of group 2 of window 1
end tell

感谢您的回复,Lauri。 我尝试了这两个建议,但好像没有任何作用。 代码运行并打开了DiskWarrior,但当安全代理弹出时就会停顿。以下是我现在的代码: tell application "DiskWarrior" activate end tell tell application "System Events" to tell process "SecurityAgent" set value of text field 2 of scroll area 1 of group 1 of window 1 to "password" click button 2 of group 2 of window 1 end tell 它仍然无法“聚焦”或“切换到”弹出窗口。 - Alex Joy
根据您所使用的OSX版本,SecurityAgent对话框具有不同的用户界面。请参阅我的答案。 - nvrtd frst

0

在Yosemite版本中,SecurityAgent对话框不同

tell application "DiskWarrior"
    open
end tell
delay 1
tell application "System Events"
    tell process "SecurityAgent"
        set value of text field 2 of window 1 to "yourPassword"
        click button 2 of window 1
    end tell
end tell

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接