在 Applescript 中使用变量命名变量
Using Variables to name Variables in Applescript
所以我想要不同的变量同名,除了末尾的数字。随着时间的推移,数字会增加,因为它处于重复循环中。
set i to 0
repeat 6 times
set i to i + 1
set SampleVar & i to i + 10
end repeat
end run
此语法可能完全错误,但我希望您能理解我想要实现的目标。
正如red_menace在评论中提到的:
You cannot dynamically create variables like that, they need to be declared at compile time. The normal way to use collections would be to use a list
or record
.
这是为使用列表重写的脚本:
set SampleList to {}
set i to 0
repeat 6 times
set i to i + 1
set the end of SampleList to i
end repeat
我不知道把它写成记录有什么好处,但它通常需要更长的时间,而且我对它们不像对列表那样熟悉。
所以我想要不同的变量同名,除了末尾的数字。随着时间的推移,数字会增加,因为它处于重复循环中。
set i to 0
repeat 6 times
set i to i + 1
set SampleVar & i to i + 10
end repeat
end run
此语法可能完全错误,但我希望您能理解我想要实现的目标。
正如red_menace在评论中提到的:
You cannot dynamically create variables like that, they need to be declared at compile time. The normal way to use collections would be to use a
list
orrecord
.
这是为使用列表重写的脚本:
set SampleList to {}
set i to 0
repeat 6 times
set i to i + 1
set the end of SampleList to i
end repeat
我不知道把它写成记录有什么好处,但它通常需要更长的时间,而且我对它们不像对列表那样熟悉。