Applescript更改:复制结果,因为列表不相同

时间:2014-10-17 10:22:01

标签: macos debugging applescript osx-lion osx-mavericks

我最近在最近的计算机上发现了一些运行它们的应用程序中的错误。这个bug来自于AppleScript提出的问题,并试图得到两个答案:文本答案和返回的按钮。基本上,这是一种脚本:

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

"将结果复制为列表是我找到保存答案的唯一方法,但问题是: 在10.7中,applescript返回此顺序的结果:返回文本,返回按钮。在10.9中,applescript以相反的顺序返回结果,首先是按钮,然后是文本。 那么使用答案是不可能的。你知道一种方法我可以保存这两个答案并使其在10.7上工作吗?与10.9一样?

2 个答案:

答案 0 :(得分:2)

尝试:

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

修改

通过将结果强制转换为列表,您无法再识别返回的按钮和文本返回的属性。

比较一下:

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

用这个:

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

答案 1 :(得分:0)

以下是adayzone答案的略有不同版本。它更像是Python的元组解包。

一衬垫:

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

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