如何处理AppleScript对话框响应?
我正在使用我编写的脚本自动将我的动态IP写入.txt文件,但我的问题是,单击退出按钮时无法关闭对话框。如何处理AppleScript对话框响应?
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
我最终什么事做了
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-06-17 04:05:10
我不知道为什么你会得到一个downvote,但这是一个upvote以及upvote的问题,我需要的只是从你的答案返回的''按钮。 – 2016-12-16 16:11:58
搞清楚如何利用压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
语句中使用该属性。
解决这个问题的另一种方法是查看文件display dialog
(它是StandardAdditions字典)的AppleScript字典(文件>打开字典...)。
添加为答案,因为没有/被点击是线“显示警报‘’”原始问题有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
我仍然困惑为什么我的问题被拒绝投票? – 2014-03-12 05:25:24
我还没有投票赞成,但这里是我的猜测......从问题详情中可以看出你的代码是如何失败的。特别是,这个短语是荒谬的:“我的问题是如果对话响应要退出,那么完成最简单的任务就是关闭applescript。” – clozach 2016-09-10 00:12:28
@clozach我的天啊。感谢不要低估,欣赏反馈。当我读到你的评论时,我在这个问题上歇斯底里地大笑起来。它完全没有意义。我在过去的3年里走得很远。我不完全确定我在回想什么时候,但我尽我所能地猜测至少有一个可理解的问题。 – 2016-09-18 23:13:46