I’m having some trouble in trying to figure out, with that AppleScript record with nested records bellow, how could I fetch the |path| key to the record that has the |open| key set to true.
set theRecords to {|556cb0f3ff0edef5|:{|path|:"/a/path", |0f529f80e5f7feff|:{|path|:"/b/path", |open|:true, ts:1.606420606631E+12}}
This is a bit of a blunt instrument, but it should work:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
set theRecords to {|556cb0f3ff0edef5|:{|path|:"/a/path", |0f529f80e5f7feff|:{|path|:"/b/path", |open|:true, ts:1.606420606631E+12}}}
set theRecords to current application's NSDictionary's dictionaryWithDictionary:theRecords
set theValues to theRecords's allValues()
return (my checkRecords:theValues) as text
on checkRecords:theValues
repeat with aRec in theValues
if (aRec's isKindOfClass:(current application's NSDictionary)) then
set openVal to (aRec's objectForKey:"open")
if openVal is not missing value and openVal's boolValue() is true then
return (aRec's objectForKey:"path")
else
(my checkRecords:(aRec's allValues()))
end if
end if
end repeat
end checkRecords:
If it’s a straight-down record nest with no intermediate lists, there’s also this vanilla solution:
set theRecords to {|556cb0f3ff0edef5|:{|path|:"/a/path", |0f529f80e5f7feff|:{|path|:"/b/path", |open|:true, ts:1.606420606631E+12}}}
set openPath to getOpenPath(theRecords)
on getOpenPath(nestedRecords)
set thisRecord to nestedRecords & {|open|:false}
repeat
if (thisRecord's |open|) then return thisRecord's |path|
set thisRecord to (beginning of thisRecord's records) & {|open|:false}
end repeat
end getOpenPath