I’ve read through many posts on records and quickly searching big lists or finding the position/index of an item in a long list. However, I can’t figure out a good way to do what I need to do (without just using a repeat loop to step through the whole list of records).
I have a list of records such as this:
{num:8808, datetime:"2020-07-24T14:32:00", caption:"Middle of nowhere", lat:"57.59631", lon:"-13.68732", notes:"Photographer: Jane Smith", lens:"Fujinon Super EBC 23mm"}
The num property can be used to match a file (e.g. DSCF8808.jpg), and when I’m processing that file, I need to access the record. So I need a quick way of locating the record so I can then access the other properties. In an ideal world, I would be able to do the following:
set vPhotoDetails to vPhotoDetails & {num:8808, datetime:"2020-07-24T14:32:00", caption:"Middle of nowhere", lat:"57.59631", lon:"-13.68732", notes:"Photographer: Jane Smith", lens:"Fujinon Super EBC 23mm"}
set vFileIndex to hGetFileIndex("DSCF8808.jpg") --> vFileIndex = 8088
set vPhotoRecord to (item of vPhotoDetails whose num = vFileIndex) --> vPhotoRecord = {num:8808, datetime:"2020-07-24T14:32:00", caption:"Middle of nowhere", lat:"57.59631", lon:"-13.68732", notes:"Photographer: Jane Smith", lens:"Fujinon Super EBC 23mm"}
Now, I know the last line is not valid AppleScript, which is my whole problem! Is there an elegant way to do this in a handler without resorting to:
on hGetRecordIndex(vRecords, vFileIndex)
set vRecordNum to 1
repeat with vRecord in vRecords
if (num of vRecord) = (vFileIndex as integer) then return vRecordNum
set vRecordNum to vRecordNum + 1
end repeat
return null
end hGetRecordIndex
My concern is that this handler will be quite slow if vRecords is a large list. Any advice much appreciated!