Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a list of records in applescript

I need a list of records created using applescript. I'm trying to create a Java like Hash Table in Applescript.

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"}

I need a way to create this structure in a way, that I can access the following:

Iterate through the list, get the individual items and for each item get the brand.

I tried this

say brand of (item 1 of grocery_list)

But this gave me an error

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

Any recommended way to implement this ?

Thanks in advance

like image 206
Silican Avatar asked Sep 15 '13 18:09

Silican


People also ask

What script does Apple use?

What Is AppleScript? AppleScript is a scripting language created by Apple. It allows users to directly control scriptable Macintosh applications, as well as parts of macOS itself.


1 Answers

You were close:

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)
like image 146
adayzdone Avatar answered Sep 23 '22 11:09

adayzdone