Applescript-在Repeat中创建递增变量名?

Applescript-在Repeat中创建递增变量名?,applescript,Applescript,我不熟悉脚本,所以我可能不知道如何寻找解决方案;到目前为止,我还没有找到答案。是否可以在循环中更改变量名 我想创建一个循环,为每个列表值创建一个新变量。这段代码现在可以工作了,但是如何将If语句更改为Repeat choose from list {"1 Apple", "2 Banana", "3 Cat", "4 Dog", "5 Elephant"} with title "What columns do you want?" with multiple selections allowe

我不熟悉脚本,所以我可能不知道如何寻找解决方案;到目前为止,我还没有找到答案。是否可以在循环中更改变量名

我想创建一个循环,为每个列表值创建一个新变量。这段代码现在可以工作了,但是如何将If语句更改为Repeat

choose from list {"1 Apple", "2 Banana", "3 Cat", "4 Dog", "5 Elephant"} with title "What columns do you want?" with multiple selections allowed
set listreturn to result
set numfields to count of listreturn

if numfields is equal to 1 then
    set field1 to word 1 of item 1 of listreturn as integer
else if numfields is equal to 2 then
    set field1 to word 1 of item 1 of listreturn as integer
    set field2 to word 1 of item 2 of listreturn as integer
else if numfields is equal to 3 then
    set field1 to word 1 of item 1 of listreturn as integer
    set field2 to word 1 of item 2 of listreturn as integer
    set field3 to word 1 of item 3 of listreturn as integer
else if numfields is equal to 4 then
    set field1 to word 1 of item 1 of listreturn as integer
    set field2 to word 1 of item 2 of listreturn as integer
    set field3 to word 1 of item 3 of listreturn as integer
    set field4 to word 1 of item 4 of listreturn as integer
end if
试着这样做:

repeat numbfields times
    set field(repeatcount) to word 1 of item (repeatcount) of listreturn
end repeat

不能在运行时创建动态变量名

解决方案是将
字段
变量放入另一个列表中

set fieldList to {field1, field2, field3, field4, field5}

choose from list {"1 Apple", "2 Banana", "3 Cat", "4 Dog", "5 Elephant"} with title "What columns do you want?" with multiple selections allowed
set listreturn to result
if listreturn is false then return
repeat with i from 1 to count listreturn
    set item i of fieldList to word 1 of item i of listreturn as integer
end repeat