It seems that using ‘where’ or ‘whose’ to filter or search a list is much more efficient than manually searching with a repeat command, but these searches only seem to work with classes:
tell app "Address Book"
get every person whose name is "John Doe"
end tell
works fine since person is a class, but the following doesn’t work:
set alist to {color:"red", itsname:"johnny"}
copy {color:"orange", itsname:"freddy"} to end of alist
set mything to first item in (get every alist where myname is "freddy"}
doesn’t compile because it says it expects a class where “alist” is in the last line. So if we try to make a class like this:
set alist to {class:things, itsname:"johnny"}
copy {class:things, itsname:"freddy"} to end of alist
set mything to first item in (get every things where myname is "freddy"}
it still doesn’t work , with the same error (“things” is an identifier, not a class, according to the compiler). Even if we use the default list class type ‘record’, it doesn’t work:
set alist to {color:"red", itsname:"johnny"}
copy {color:"orange", itsname:"freddy"} to end of alist
set mything to first item in (get every record where myname is "freddy"}
this time cause it says it expects a “,” where the “}” is in the last line!?
I’ve even tried making a class using the “script myclass” command but that doesn’t allow filters to be applied on it either.
Any ideas how to create a valid new class that can have filters applied to it? Do you have to define a filter method somehow?
thanks in advance!