单击 NSAlert 中按钮的 AppleScript 代码

发布于 2024-11-10 04:58:49 字数 539 浏览 4 评论 0原文

我有一个 Mac 应用程序,一旦打开(在 awakeFromNib 中),就会向用户显示一个带有两个按钮的 NSAlert,一个带有“Option1”,另一个带有“Option2”。我想自动执行以下流程:

  1. 从“应用程序”文件夹中打开应用程序。
  2. 通过单击 NSAlert 中的按钮选择“Option2”

到目前为止,我只完成了第一部分:

tell application "Finder"
activate
make new Finder window to startup disk
open application file "My Application.app" of folder "Applications" of startup disk
close Finder window 1
end tell

任何人都可以帮助我编写代码吗?我知道我可以使用系统事件命令来捕获此单击事件,但无法在网上找到任何帮助来单击 NSAlert 中的按钮,而不是在常规窗口中。

I have an mac application that once opened (in awakeFromNib) shows the user an NSAlert with two buttons, one with "Option1", the other with "Option2". I would like to automate the following flow:

  1. Open the application from the Applications folder.
  2. Choose "Option2" by clicking the button in the NSAlert

So far I've managed to do only the first part:

tell application "Finder"
activate
make new Finder window to startup disk
open application file "My Application.app" of folder "Applications" of startup disk
close Finder window 1
end tell

Can anybody help me with the code? I understand that I can use the System Events commands to catch this click event, but can't manage to find any help online for clicking a button in an NSAlert, and not in a regular Window.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梨涡 2024-11-17 04:58:49

你可以试试这个...

tell application "My Application" to activate

delay 5

tell application "System Events"
    tell process "My Application"
       click button "option 2" of window 1
    end
end

You might try this...

tell application "My Application" to activate

delay 5

tell application "System Events"
    tell process "My Application"
       click button "option 2" of window 1
    end
end
蓝咒 2024-11-17 04:58:49

您打开了多少个窗户?大概是越来越混乱了。

如果您需要程序UI浏览器,通常可以找到GUI脚本的正确术语。我不确定是否值得为此购买,但您可以在演示模式下运行该程序一个月,并使用它来找到合适的条款。

http://pfiddlesoft.com/uibrowser/

How many windows do you have open? It's probably getting confused.

If you need to the program UI Browser can generally find the proper terms for GUI Scripting. I'm not sure it's worth buying just for this but you can run the program in demo mode for a month and use it to find the proper terms.

http://pfiddlesoft.com/uibrowser/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文