简体   繁体   中英

Applescript changes : copy the result as list isn't the same

I recently discover a bug in some of my applescripts running them on recent computers. The bug come from questions the applescript asks and try to get two answers : the text answer and the button which is returned. Basically, this is the kind of script :

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"}

The "copy the result as list is the only way I found to save both the answers, but here is the problem : In 10.7, applescript returns the result this order : text returned, button returned. And in 10.9, applescript returns the result in the opposite order, first the button, then the text. Then using the answers is impossible. Do you know a way I could save both of the answers and make it work on 10.7 as on 10.9 ?

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 coercing the result to a list, you can no longer identify the button returned and text returned properties.

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

Here is a slightly different version of adayzone's answer. It read more like Python's tuple unpacking.

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 the result intermediary variable:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM