【发布时间】:2018-01-06 02:34:29
【问题描述】:
我不太清楚这一点,我才刚刚开始编写脚本。为了解释,我想使用下面的代码来允许用户从列表中选择一个项目。然后,我想将他们选择的内容转换为列表中的数字位置。
例如,如果用户选择了 iPod,我希望它将他们的输入保存为 2 而不是 iPod。
这是我所拥有的:
set productList to {"iPad", "iPod", "iPhone", "Mac", "Apple TV", "Apple Watch", "Beats", "Apple Watch Edition", "Apple Watch Hermes"}
set yourProduct to choose from list of productList with prompt "Select your product: "
on listPosition(this_item, this_list)
repeat with i from 1 to the count of this_list
if item i of this_list is this_item then return i
end repeat
return 0
end listPosition
set item_num to my listPosition(yourProduct, productList)
【问题讨论】:
标签: javascript arrays arraylist applescript