如何处理AppleScript对话框响应?

Isa*_*ner 2 applescript

我正在使用我编写的脚本自动将动态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
Run Code Online (Sandbox Code Playgroud)

Isa*_*ner 10

我最终做的是

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
Run Code Online (Sandbox Code Playgroud)

您可以使用您要运行的任何代码替换行"显示警报"否/是单击""


Joh*_*uer 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
Run Code Online (Sandbox Code Playgroud)

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

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