SirWafflesIIV

Q: How do you get both a button returned and a text returned from a single dialog?

For example:

 

display dialog "Hello!" default answer "" buttons {"Hi!"}

set x to the text returned of the result

set y to the text returned of the result


^ This will get the result of x for y. How is it possible to get x and y from the dialog?

MacBook Air (13-inch Late 2010), OS X Yosemite (10.10.5)

Posted on Sep 30, 2016 6:55 PM

Close

Q: How do you get both a button returned and a text returned from a single dialog?

  • All replies
  • Helpful answers

  • by Niel,

    Niel Niel Sep 30, 2016 6:56 PM in response to SirWafflesIIV
    Level 10 (314,476 points)
    Mac OS X
    Sep 30, 2016 6:56 PM in response to SirWafflesIIV

    Here:

     

    display dialog "Hello!" default answer "" buttons {"Hi!"}

    set {x, y} to {text returned of the result, button returned of the result}

     

    (145016)

  • by Hiroto,

    Hiroto Hiroto Sep 30, 2016 7:25 PM in response to SirWafflesIIV
    Level 5 (7,348 points)
    Sep 30, 2016 7:25 PM in response to SirWafflesIIV

    Hello

     

    You may assign variable to dialog result which is indeed a record.

     

     

    set r to display dialog "Hello" default answer ""
    set x to r's button returned
    set y to r's text returned
    -- set {x, y} to r's {button returned, text returned} -- alternative
    return {r, x, y}
    

     

     

    Regards,

    H

  • by Camelot,

    Camelot Camelot Sep 30, 2016 9:06 PM in response to SirWafflesIIV
    Level 8 (47,352 points)
    Mac OS X
    Sep 30, 2016 9:06 PM in response to SirWafflesIIV

    For context, the result is always the result of the previous command. So in your example, when you get to the line:

     

    set y to the text returned of the result


    the result is the result of the line:

     

    set x to the text returned of the result


    and hence no longer refers to the dialog because that was too far back.

     

    As others have pointed out, either store the result of the display dialog in a variable, so you're not bound to the one-line restriction of the result, or extract both values in one go.