组织脚本的结果
Organize the results of an script
脚本的结果给了我一些简化的东西,看起来像这样:
{{"First", "Second"}, {"Third", "Fourth"}}
我想以一种简单的方式向用户展示它。像这样:
列表 1:第一,第二
清单 2:第三、第四
我知道嵌套信息只有两层。但是我不知道每个列表中有多少个列表或项目。
如何以清晰、简单的方式向用户显示脚本的结果?
以下示例 AppleScript 代码 将构建要显示的消息不管返回多少列表。
由于您没有包含任何代码,我正在设置基本的变量来处理整个过程。
set theLists to {{"First", "Second"}, {"Third", "Fourth", "Fifth"}, ¬
{"Sixth", "Seventh"}, {"Eight", "Ninth", "Tenth", "Eleventh"}}
set theListCount to count theLists
set theMsg to ""
set text item delimiters to ", "
repeat with i from 1 to theListCount
if i < theListCount then
set theMsg to theMsg & "Group " & i & ": " & item i of theLists & linefeed
else
set theMsg to theMsg & "Group " & i & ": " & item i of theLists
end if
end repeat
set text item delimiters to ""
display dialog theMsg buttons {"Cancel", "OK"} default button "OK"
使用 theLists
变量 设置在 脚本 的开头来表示 lists
返回 和一组虚拟 list items
并构建一条消息以与 display dialog
一起使用,下图是 返回的示例示例 AppleScript 代码:
显然,如果您有大量的 lists
和 lists items
,那么 display dialog
将不是可行的方法,所以这只是一个示例,说明如何 枚举 list
并且将需要不同的编码以另一种方式显示,但是希望这会让您走上正轨。
否则你需要更明确和具体一些,甚至可能包括一些适当的代码。
注意:示例 AppleScript 代码 就是这样,不包含任何 error 适当处理。用户有责任根据需要或需要添加任何 错误处理 。看看 try statement and error statement in the AppleScript Language Guide. See also, Working with Errors.
脚本的结果给了我一些简化的东西,看起来像这样:
{{"First", "Second"}, {"Third", "Fourth"}}
我想以一种简单的方式向用户展示它。像这样:
列表 1:第一,第二
清单 2:第三、第四
我知道嵌套信息只有两层。但是我不知道每个列表中有多少个列表或项目。
如何以清晰、简单的方式向用户显示脚本的结果?
以下示例 AppleScript 代码 将构建要显示的消息不管返回多少列表。
由于您没有包含任何代码,我正在设置基本的变量来处理整个过程。
set theLists to {{"First", "Second"}, {"Third", "Fourth", "Fifth"}, ¬
{"Sixth", "Seventh"}, {"Eight", "Ninth", "Tenth", "Eleventh"}}
set theListCount to count theLists
set theMsg to ""
set text item delimiters to ", "
repeat with i from 1 to theListCount
if i < theListCount then
set theMsg to theMsg & "Group " & i & ": " & item i of theLists & linefeed
else
set theMsg to theMsg & "Group " & i & ": " & item i of theLists
end if
end repeat
set text item delimiters to ""
display dialog theMsg buttons {"Cancel", "OK"} default button "OK"
使用 theLists
变量 设置在 脚本 的开头来表示 lists
返回 和一组虚拟 list items
并构建一条消息以与 display dialog
一起使用,下图是 返回的示例示例 AppleScript 代码:
显然,如果您有大量的 lists
和 lists items
,那么 display dialog
将不是可行的方法,所以这只是一个示例,说明如何 枚举 list
并且将需要不同的编码以另一种方式显示,但是希望这会让您走上正轨。
否则你需要更明确和具体一些,甚至可能包括一些适当的代码。
注意:示例 AppleScript 代码 就是这样,不包含任何 error 适当处理。用户有责任根据需要或需要添加任何 错误处理 。看看 try statement and error statement in the AppleScript Language Guide. See also, Working with Errors.