# AppleScript question re return value of whose

**URL:** <https://discourse.devontechnologies.com/t/applescript-question-re-return-value-of-whose/74809>\
**Category:** Automation\
**Tags:** automation\
**Created:** [February 27, 2023, 3:25pm UTC](https://discourse.devontechnologies.com/t/applescript-question-re-return-value-of-whose/74809 "2023-02-27T15:25:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrillek](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/chrillek/32/29340_2.png) [@chrillek](https://discourse.devontechnologies.com/u/chrillek)\
**Post date:** [February 27, 2023, 3:25pm UTC](https://discourse.devontechnologies.com/t/applescript-question-re-return-value-of-whose/74809/1 "2023-02-27T15:25:46Z")

</div>

This code

```applescript
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:

```plaintext
{{}, 
{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.

---

<div class="post-metadata">

**Author:** ![cgrunenberg](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/cgrunenberg/32/7172_2.png) [@cgrunenberg](https://discourse.devontechnologies.com/u/cgrunenberg)\
**Post date:** [February 27, 2023, 3:31pm UTC](https://discourse.devontechnologies.com/t/applescript-question-re-return-value-of-whose/74809/2 "2023-02-27T15:31:36Z")

</div>

> [@chrillek](#):
>
> I thought (!) that `whose` should return a single list

It’s not specific to DEVONthink, in this case `whose` is applied to a list of lists. And therefore the result looks the same.

---

<div class="post-metadata">

**Author:** ![chrillek](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/chrillek/32/29340_2.png) [@chrillek](https://discourse.devontechnologies.com/u/chrillek)\
**Post date:** [February 27, 2023, 4:16pm UTC](https://discourse.devontechnologies.com/t/applescript-question-re-return-value-of-whose/74809/3 "2023-02-27T16:16:55Z")

</div>

Thanks for the clarification – the examples I found where only simple ones.

---

<div class="post-metadata">

**Author:** ![winter](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/w/2bfe46/32.png) [@winter](https://discourse.devontechnologies.com/u/winter)\
**Post date:** [February 27, 2023, 8:32pm UTC](https://discourse.devontechnologies.com/t/applescript-question-re-return-value-of-whose/74809/4 "2023-02-27T20:32:17Z")

</div>

`.flat()` and `.flatMap()`, are, of course, helpful here in JS.

* * *

Or in AppleScript, perhaps something like:

```applescript
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

```

---

<div class="post-metadata">

**Author:** ![chrillek](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/chrillek/32/29340_2.png) [@chrillek](https://discourse.devontechnologies.com/u/chrillek)\
**Post date:** [February 27, 2023, 9:42pm UTC](https://discourse.devontechnologies.com/t/applescript-question-re-return-value-of-whose/74809/5 "2023-02-27T21:42:46Z")

</div>

The question originally arose in a JS script 😉 then I saw that the same thing happens in AS.

`flat` etc would be ok here if it returned a one-level list in all cases, i.e. regardless of the nesting of objects `whose` is called on.

---

<div class="post-metadata">

**Author:** ![winter](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/w/2bfe46/32.png) [@winter](https://discourse.devontechnologies.com/u/winter)\
**Post date:** [February 28, 2023, 6:21am UTC](https://discourse.devontechnologies.com/t/applescript-question-re-return-value-of-whose/74809/6 "2023-02-28T06:21:27Z")

</div>

> [@chrillek](#):
>
> if it returned a one-level list in all cases

Probably worth experimenting with its _depth_ argument, which defaults to 1, but to which you can supply the special quasi-integer value `Infinity`.

[Array.prototype.flat() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat)

[Infinity - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Infinity)

---

<div class="post-metadata">

**Author:** ![system](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/2X/4/4e6ff70c96be2eb307a274d890bba8d71ba671b3.png) [@system](https://discourse.devontechnologies.com/u/system)\
**Post date:** [February 27, 2026, 6:21am UTC](https://discourse.devontechnologies.com/t/applescript-question-re-return-value-of-whose/74809/7 "2026-02-27T06:21:36Z")

</div>

This topic was automatically closed 1095 days after the last reply. New replies are no longer allowed.
