Applescript changes: copy the result as the list is not the same

I recently discovered a bug in some of my applications running them on recent computers. The error comes from the questions applescript asks and try to get two answers: a text response and a return button. Basically, this is a script type:

display dialog "This is a question" default answer "the text answer" buttons {"button 1", "button2", "button 3"}
copy the result as list to {"the_text", "the_button"}

      

"Copying the result as a list is the only way I've found to keep both answers, but here's the problem: In 10.7 applescript returns the result in that order: text is returned, the button is returned. And in 10.9 applescript returns the result in the opposite order, button first. then text. Then using answers is not possible. Do you know a way that I could save both answers and make it work from 10.7 to 10.9?

+3


source to share


2 answers


Try:

set {text returned:the_text, button returned:the_button} to display dialog "This is a question" default answer "the text answer" buttons {"button 1", "button2", "button 3"}

      

EDIT

By forcing the result to a list, you can no longer identify the returned button and the properties returned by the text.



Compare this:

display dialog "This is a question" default answer "the text answer" buttons {"button 1", "button2", "button 3"}

      

with this:

display dialog "This is a question" default answer "the text answer" buttons {"button 1", "button2", "button 3"}
return the result as list

      

+2


source


Here's a slightly different version of adayzone's answer. This is more like unpacking Python tuples.

One-liner:

set {the_text, the_button} to {text returned, button returned} of (display dialog "This is a question" default answer "the text answer" buttons {"button 1", "button2", "button 3"})

      



Using an intermediate variable result

:

display dialog "This is a question" default answer "the text answer" buttons {"button 1", "button2", "button 3"}
set {the_text, the_button} to {text returned, button returned} of the result

      

0


source







All Articles