Isaiah Turner Isaiah Turner - 2 months ago 24
AppleScript Question

How can I handle AppleScript dialog response?

I am using a script that I wrote to automatically write my dynamic ip to a .txt file. My problem is that I can not get the dialog to close when the quit button is clicked.

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

Answer

The simplest way to figure out how to make use of yn's button pressed is to look at 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

You'll see that yn returns {button returned:"Quit", gave up:false}. This indicates that yn has a property button returned that you can use in your if statement.

Another way to figure this out is to look through the AppleScript dictionary (File > Open Dictionary...) that documents display dialog, which is the StandardAdditions dictionary.