简体   繁体   English

Applescript更改:复制结果列表不一样

[英]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. 这个bug来自于AppleScript提出的问题,并试图得到两个答案:文本答案和返回的按钮。 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 ? “将结果复制为列表是我发现保存答案的唯一方法,但问题是:在10.7中,applescript返回结果此顺序:返回文本,返回按钮。在10.9中,applescript返回结果相反的顺序,首先是按钮,然后是文本。然后使用答案是不可能的。你知道一种方法我可以保存两个答案并使其在10.7上工作,如同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. 这是adayzone的答案略有不同的版本。 It read more like Python's tuple unpacking. 它更像是Python的元组解包。

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: 使用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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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