Applescript dialog with giving up

Discussion in 'Mac Programming' started by Asu, Nov 7, 2016.

  1. Asu macrumors member

    Asu

    Joined:
    Apr 28, 2006
    #1
    I have another question regarding these dialogs: Is there a way to display the countdown of seconds in the dialog display?

    Thanks

    Asu
     
  2. Red Menace macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #2
    To do any kind of custom UI stuff, you would need to use something like AppleScriptObjC to access the Cocoa API - regular AppleScript doesn't have any dialog customizations available, although you could perform a hack such as repeatedly showing a dialog that times out, for example:

    Code:
    set countdown to 20
    set interval to 2
    
    repeat with timer from countdown to 1 by -interval
        if timer ≤ interval then set interval to timer
        set theResult to display dialog "Should I do something?" & return & timer & " seconds left" buttons ¬
            {"Yes", "No", "Maybe"} default button "Yes" with icon caution giving up after interval
        if (button returned of theResult) is "Yes" then
            say "Yes"
            exit repeat
        else if (button returned of theResult) is "Maybe" then
            say "Maybe"
        else if timer ≤ interval or (button returned of theResult) is "No" then
            say "No"
            exit repeat
        end if
    end repeat
    
     
  3. Asu thread starter macrumors member

    Asu

    Joined:
    Apr 28, 2006
    #3
    --- Post Merged, Nov 12, 2016 ---
    Wow this is really clever, thanks!
     

Share This Page