如何在applescript中创建记录列表

时间:2013-09-15 18:27:17

标签: applescript hashtable

我需要使用applescript创建的记录列表。我正在尝试在Applescript中创建一个像Hash Table这样的Java。

set grocery_list to {"milk", "butter", "eggs"}
set milk to {name:"Whole Milk", quantity:"1 Gallon", brand:"Newland Farms" }
set butter to {name:"Unsalted Butter", quantity:"1 pound", brand:"Land O Lakes"}
set eggs to {name:"Grade A jumbo eggs", quantity:"1 dozen", brand:"Farm Fresh"}

我需要一种方法来创建这种结构,我可以访问以下内容:

遍历列表,获取各个项目,并为每个项目获得品牌。

我试过这个

say brand of (item 1 of grocery_list)

但这给了我一个错误

Can’t get brand of \"milk\"." number -1728 from brand of "milk"

任何推荐的实现方式?

提前致谢

1 个答案:

答案 0 :(得分:6)

你很亲密:

set milk to {|name|:"Whole Milk", quantity:"1 Gallon", brand:"Newland Farms"}
set butter to {|name|:"Unsalted Butter", quantity:"1 pound", brand:"Land O Lakes"}
set eggs to {|name|:"Grade A jumbo eggs", quantity:"1 dozen", brand:"Farm Fresh"}

set grocery_list to {milk, butter, eggs}

say brand of (item 1 of grocery_list)