2

我正在使用我编写的脚本来自动将我的动态 IP 写入 .txt 文件,但我的问题是当单击退出按钮时我无法关闭对话框。

set yn to (display dialog "Your ip has been written to the server, the application will re-run in 10 minutes if you DO NOT close this window." buttons {"Quit", "Run again"} giving up after 600)
if yn is equal to "Quit" then
quit
end if
4

4 回答 4

15

我最终做的是

display alert "This is an alert" buttons {"No", "Yes"}
if button returned of result = "No" then
     display alert "No was clicked"
else
    if button returned of result = "Yes" then
         display alert "Yes was clicked"
    end if
end if

您可以用您要运行的任何代码替换“显示警报“否/是被点击””行

于 2013-03-03T17:26:54.013 回答
6

弄清楚如何使用yn按下的按钮的最简单方法是查看yn

set yn to (display dialog "Your ip has been written to the server, the application will re-run in 10 minutes if you DO NOT close this window." buttons {"Quit", "Run again"} giving up after 600)
return yn

你会看到yn返回{button returned:"Quit", gave up:false}。这表明它yn有一个button returned可以在if语句中使用的属性。

解决这个问题的另一种方法是查看文档的 AppleScript 字典(文件 > 打开字典...),display dialog即 StandardAdditions 字典。

于 2013-03-02T04:00:48.947 回答
1

要添加作为原始问题的答案,giving up after如果对话框确实超过了超时期限,我需要在我的脚本中做一些事情。这是考虑超时的附加选项:

set dialogTitle to "Star Wars Question"
set theDialog to display alert "Do you think Darh Maul should have his own movie?" buttons {"YES", "NO"} default button "YES" giving up after 10
if button returned of theDialog = "" then
    display notification "No decision was made, cancelled dialog" with title dialogTitle
else if button returned of theDialog = "YES" then
    display notification "I concur" with title dialogTitle
else if button returned of theDialog = "NO" then
    display notification "I find your lack of faith disturbing" with title dialogTitle
end if
于 2016-12-16T16:21:40.337 回答
0
display dialog ("An example dialog.") buttons {"Cancel", "OK"}

if button returned of result = "Button" then
 display dialog ("You clicked Button.")
end
于 2020-11-15T23:31:52.510 回答