# Any efficient way to get all actions list?

**URL:** <https://forums.creativeclouddeveloper.com/t/any-efficient-way-to-get-all-actions-list/4013>\
**Category:** UXP Plugin API\
**Tags:** uxp, javascript\
**Created:** [December 11, 2021, 3:19pm UTC](https://forums.creativeclouddeveloper.com/t/any-efficient-way-to-get-all-actions-list/4013 "2021-12-11T15:19:29Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [December 11, 2021, 3:19pm UTC](https://forums.creativeclouddeveloper.com/t/any-efficient-way-to-get-all-actions-list/4013/1 "2021-12-11T15:19:29Z")

</div>

Is there an efficient way to get full actions list? Preferably with parent (actionSet) name. Currently constructing a list of the 12 default actions (in one set) takes ~2 seconds (using `forEach` even up to 3 secs)

```auto
    const result = []

    const start = new Date().getTime();

    for (let actionSet of photoshop.app.actionTree ?? []) {
        for (let action of actionSet.actions ?? []) {
            const item = {
                title: action.name,
                data: {path: [actionSet.name, action.name]},
                description: actionSet.name,
            }

            result.push(item)
        }
    }

    const end = new Date().getTime();

    console.log("FOR", end - start);

```

Was thinking maybe some property that we could get with batchPlay?

---

<div class="post-metadata">

**Author:** ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)\
**Post date:** [December 11, 2021, 9:56pm UTC](https://forums.creativeclouddeveloper.com/t/any-efficient-way-to-get-all-actions-list/4013/2 "2021-12-11T21:56:20Z")

</div>

Sure.

- use batchplay getter to read action set at index 1
- if exists then read its number of childern
- then you can create an array of descriptors and get its content also by index since you know number of items then you know where to stop
- repeat similar for its childs

Alchemist can help you to generate getter. You might need to replace ID with index.

---

<div class="post-metadata">

**Author:** ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)\
**Post date:** [December 11, 2021, 10:00pm UTC](https://forums.creativeclouddeveloper.com/t/any-efficient-way-to-get-all-actions-list/4013/3 "2021-12-11T22:00:12Z")

</div>

Alchemist is using this internally. [alchemist/GetInfo.ts at master · jardicc/alchemist · GitHub](https://github.com/jardicc/alchemist/blob/master/src/inspector/classes/GetInfo.ts#L380)

Not sure if this will help since this file is a mess and I didn’t want to spend too much time with it since later I can replace its parts with DOM. 😃 But considering performance I have to decide whether to do that.

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [December 11, 2021, 10:13pm UTC](https://forums.creativeclouddeveloper.com/t/any-efficient-way-to-get-all-actions-list/4013/4 "2021-12-11T22:13:01Z")

</div>

I appreciate the answer, but I don’t understand 🤔

In the code I see you already have IDs, but how do you get them?

> - use batchplay getter to read action set at index 1

But how do you get that action set? What would the descriptor be?

Or do you mean I should get action sets from `photoshop.app.actionTree` and then loop through them to get actions?

---

<div class="post-metadata">

**Author:** ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)\
**Post date:** [December 11, 2021, 10:15pm UTC](https://forums.creativeclouddeveloper.com/t/any-efficient-way-to-get-all-actions-list/4013/5 "2021-12-11T22:15:37Z")

</div>

![image](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/7/79c78300536dad47be563dcd3a847238219daa47.png)  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/8/89bd52e109efec6f73f719d3654c421187b498e0.png)

replace `_id` with `_index:1`

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [December 12, 2021, 12:17am UTC](https://forums.creativeclouddeveloper.com/t/any-efficient-way-to-get-all-actions-list/4013/6 "2021-12-12T00:17:07Z")

</div>

So getting number of action sets is still through DOM with something like `photoshop.app.actionTree.length`?

---

<div class="post-metadata">

**Author:** ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)\
**Post date:** [December 12, 2021, 12:50am UTC](https://forums.creativeclouddeveloper.com/t/any-efficient-way-to-get-all-actions-list/4013/7 "2021-12-12T00:50:39Z")

</div>

I wouldn’t do that… I would try “count” property.

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [December 12, 2021, 12:54am UTC](https://forums.creativeclouddeveloper.com/t/any-efficient-way-to-get-all-actions-list/4013/8 "2021-12-12T00:54:56Z")

</div>

So how do you get count of action sets? Both in Alchemist code and here in screenshots I see descriptors where you already have the sets 😕

---

<div class="post-metadata">

**Author:** ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)\
**Post date:** [December 12, 2021, 12:57am UTC](https://forums.creativeclouddeveloper.com/t/any-efficient-way-to-get-all-actions-list/4013/9 "2021-12-12T00:57:56Z")

</div>

See the second screenshot “count” property of any action set. This tells you the number of sets in total. If you add more then value will increment starting with zero.

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [December 12, 2021, 9:47am UTC](https://forums.creativeclouddeveloper.com/t/any-efficient-way-to-get-all-actions-list/4013/10 "2021-12-12T09:47:25Z")

</div>

OK, this got me so confused - zero based `count === 0` means there’s one set and the totally opposite one based index (probably someone at Adobe mixed up the buttons when implementing). Also having sets count on every set… 🤦‍♂️ Can you delete all sets? What’s the count then? Don’t see how I can restore default set, so not too brave to test it 🙂 I guess then you can’t get count at all, because there are no sets 😃

---

<div class="post-metadata">

**Author:** ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)\
**Post date:** [December 12, 2021, 10:29am UTC](https://forums.creativeclouddeveloper.com/t/any-efficient-way-to-get-all-actions-list/4013/11 "2021-12-12T10:29:27Z")

</div>

Yes you can’t 😃 …

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [December 12, 2021, 11:15am UTC](https://forums.creativeclouddeveloper.com/t/any-efficient-way-to-get-all-actions-list/4013/12 "2021-12-12T11:15:47Z")

</div>

So my final code now is:

```auto
const getActions = () => {
    const result = []

    for (let action of getAppActions() ?? []) {
        const item= {
            title: action.name,
            data: {path: [action.parentName, action.name]},
            description: action.parentName,
        }

        result.push(item)
    }

    return result
}

const getAppActions = () => {
    const setsCount = bp([
        {
            "_obj": "get",
            "_target": [
                {"_ref": "actionSet", "_index": 1},
            ],
            "_options": {"dialogOptions": "dontDisplay"}
        }
    ])[0].count ?? null

    if (setsCount === null) {
        return []
    }

    const setsDescriptors = []

    for (let i = 1; i <= setsCount + 1; i++) {
        setsDescriptors.push(
            {
                "_obj": "get",
                "_target": [
                    {"_ref": "actionSet", "_index": i}
                ],
                "_options": {"dialogOptions": "dontDisplay"}
            }
        )
    }

    const setsData = bp(setsDescriptors)

    if (!setsData.length) {
        return []
    }

    const actionsDescriptors = []

    for (let i = 0; i < setsData.length; i++) {
        let setData = setsData[i]

        if (!setData.numberOfChildren) {
            continue
        }

        for (let j = 1; j <= setData.numberOfChildren; j++) {
            actionsDescriptors.push(
                {
                    "_obj": "get",
                    "_target": [
                        {"_ref": "actionSet", "_index": j},
                        {"_ref": "actionSet", "_index": setData.itemIndex},
                    ],
                    "_options": {"dialogOptions": "dontDisplay"}
                }
            )
        }
    }

    const actionsData = bp(actionsDescriptors)

    return actionsData || []
}

```

Basically:

- Get count of sets
- Get data for these sets
- Get actions for each set containing children

These 3 BatchPlays and looping to get custom structure takes 20-100 ms in total (instead of previous 2 seconds)

---

<div class="post-metadata">

**Author:** ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)\
**Post date:** [December 12, 2021, 2:41pm UTC](https://forums.creativeclouddeveloper.com/t/any-efficient-way-to-get-all-actions-list/4013/13 "2021-12-12T14:41:20Z")

</div>

Yes, that is what I meant. 🙂 But check what happens if you have exactly one actionSet or none. Just to be sure 🙂 I would expect this to fail when there is none.

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [December 12, 2021, 2:58pm UTC](https://forums.creativeclouddeveloper.com/t/any-efficient-way-to-get-all-actions-list/4013/14 "2021-12-12T14:58:28Z")

</div>

I think this should take care of it

```auto
    const setsCount = bp(descriptors)[0].count ?? null

    if (setsCount === null) {
        return []
    }

```

I’ll try it later on beta after I backup the default set

---

<div class="post-metadata">

**Author:** ![AAverin](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/aaverin/32/1368_2.png) [@AAverin](https://forums.creativeclouddeveloper.com/u/AAverin)\
**Post date:** [November 25, 2023, 2:15pm UTC](https://forums.creativeclouddeveloper.com/t/any-efficient-way-to-get-all-actions-list/4013/15 "2023-11-25T14:15:56Z")

</div>

@Karmalakas Is your solution still the best thing to do when getting all actions in sets?

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [November 25, 2023, 2:41pm UTC](https://forums.creativeclouddeveloper.com/t/any-efficient-way-to-get-all-actions-list/4013/16 "2023-11-25T14:41:21Z")

</div>

Don’t know. Would need to revisit and test if DOM has improved, but I believe BP is still the closest to Ps internals, that we have access to, so it should be faster anyway
