Applescript Display Dialog - for real

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

  1. Asu macrumors member

    Asu

    Joined:
    Apr 28, 2006
    #1
    Hello,

    I need to capture whether a dialog gave up or not.


    tell application "Finder"
    display dialog "Do you want to do something?" giving up after 10
    if <did give up after 10> then
    do one thing
    else
    do another thing
    end if
    end
    tell

    Thanks!

    Asu
     
  2. Red Menace macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #2

    The result of display dialog is a record
    , with properties depending on the parameters used, so you can just query the desired value - for example:

    Code:
    set dialogResult to (display dialog "Do you want to do something?" giving up after 10)
    if gave up of dialogResult then
        log "I gave up"
    else
        log button returned of dialogResult
    end if
    Note that display dialog is a part of StandardAdditions, so you do not need to use the Finder.
     
  3. Asu thread starter macrumors member

    Asu

    Joined:
    Apr 28, 2006
  4. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #4
    I can't believe I'd never noticed that there's a "gave up" record returned! Every day's a school day...
     

Share This Page