Query in AS Records

Hi I would like ti know is is possible to ask the following thing using AS:

Example

set myList to {{city:“London”, country:“UK”}, {city:“Los Angeles”, country:“USA”}, {city:“manchester”, country:“UK”}}

I would like to count all record whose country is “UK”

with something like:

set countryCounter to every record whose country is “UK”

But this seems not possible. Is AS limit and I need to iterate through records or there is workaround?

Thanks in advance

Ame

Hello.

As you have organized it now, you’ll have to iterate, but if your table of records where stored in a property list file, you’d be able to perform a query to attain all records whose city is London. (Not necessarily the correct syntax, but something along those lines.)

Another option could be to store your records in a spreadsheet, and perform the query through them, you could also use database events, or store your records in a csv text file, and use the shell tools like awk for retrieving the correct records, (or Applescript).

Records are indeed very basic but some applications can filter (or as you name query) items from an record and or list. Shane has developed an faceless application like system events called ASObjC Runner with a lot of features that are missing in standard AppleScript.

Your code would look like:

set myList to {{city:"London", country:"UK"}, {city:"Los Angeles", country:"USA"}, {city:"manchester", country:"UK"}}

tell application "ASObjC Runner"
	return refine list myList using predicates "country = \"UK\""
end tell