tell application id "DNtp"
set result to (contents of databases) whose name contains "xxx"
end tell
creates a “list of lists” structure in result: One list for each database, and in each of these lists the matching records found in that database:
{{},
{content id 82535 of database id 5},
{content id 8412 of database id 7, content id 8374 of database id 7, …},
{},
{content id 2873 of database id 4, content id 5178 of database id 4,…},
{},
{},
{}}
I thought (!) that whose should return a single list, namely of the records it found. Is this return construct a feature of whose or a specialty of DT? In my mind, a list of records would be perfectly fine since they contain a database property.
.flat() and .flatMap(), are, of course, helpful here in JS.
Or in AppleScript, perhaps something like:
on run
flatten({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}})
end run
on flatten(xs)
script
on f(vs)
if list is class of vs then
set n to length of vs
set a to {}
repeat with i from 1 to n
set a to a & f(item i of vs)
end repeat
else
vs
end if
end f
end script
f(xs) of result
end flatten