Applescript将列表中的每个项目保存为文本

时间:2016-08-06 18:37:23

标签: arrays list applescript

我有一个数字列表(数字的数量是随机的)

例如,这是我当前的结果:

pip install tabular==0.0.8

我想将它们打印在文本文件中,或保存在剪贴板中,但这不起作用

Result:
{"1024343495", "84734348416", "100434439171", "86343425", "13434290", "83434946", "81711343497", "43534347319", "863434490"}

所以我尝试将all转换为字符串:

set the clipboard to myList

然后我只有一个巨大的数字: 1024343495847343484161004344391718634342513434290834349468171134349743534347319863434490

2 个答案:

答案 0 :(得分:1)

尝试

set myString to ""
set i to 0
repeat (number of items in myList) times
    set i to i + 1
    set myString to myString & ((item i of myList)as string) &  ", "-- this last bit here is what goes in between each list item
end repeat
return myString

结果“1024343495,84734348416,100434439171”-etc

答案 1 :(得分:0)

您可以在相应地设置text item delimiters之后使用您的代码。

set myList to {"1024343495", "84734348416", "100434439171", "86343425", "13434290", "83434946", "81711343497", "43534347319", "863434490"}
set {TID, text item delimiters} to {text item delimiters, ", "}
set the clipboard to myList as text
set text item delimiters to TID