Search code examples
applescript

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 but my problem is that I cannot 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

Solution

  • What I ended up doing was

    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
    

    You can replace the lines "display alert "No/Yes was clicked"" with whatever code you want to run