# How to select all layers

**URL:** <https://forums.creativeclouddeveloper.com/t/how-to-select-all-layers/7327>\
**Category:** Photoshop\
**Tags:** uxp\
**Created:** [January 8, 2024, 4:58am UTC](https://forums.creativeclouddeveloper.com/t/how-to-select-all-layers/7327 "2024-01-08T04:58:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![meatloaf\_18](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@meatloaf\_18](https://forums.creativeclouddeveloper.com/u/meatloaf_18)\
**Post date:** [January 8, 2024, 4:58am UTC](https://forums.creativeclouddeveloper.com/t/how-to-select-all-layers/7327/1 "2024-01-08T04:58:22Z")

</div>

Hi All, Im very new with UXP.  
This whole async, await, executeAsModal are still hard for me to grasp. The syntax as well.  
What I want to do is to automatically select all layers in the activeDocument (doesnt matter if they’re visible or not) then nest them all in one smart object.  
The smart object part is something I can copy from alchemist.  
But the selecting all part is what i cant figure out. In alchemist, the listener records the name/id of the layer you selected. Im not sure how to replace it with a variable.  
In the old scripting menthod, this is something I can easily do. Totally have no idea how to do it in UXP.  
Any help would be greatly appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![meatloaf\_18](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@meatloaf\_18](https://forums.creativeclouddeveloper.com/u/meatloaf_18)\
**Post date:** [January 8, 2024, 5:38am UTC](https://forums.creativeclouddeveloper.com/t/how-to-select-all-layers/7327/2 "2024-01-08T05:38:32Z")

</div>

Never mind, after sometime, finally came up with something that works:

async function selectAllLayers(){  
function actionCommands() {  
const app = require(“photoshop”).app;  
const layers = app.activeDocument.layers;

```
  for (i = 0; i < layers.length; i++) {
      let layer = layers[i];
      if (!layer.selected) {
      layer.selected = true;
    }
  }

```

}

await require(‘photoshop’).core.executeAsModal(actionCommands, {“commandName”: “select all layers”});  
}

---

<div class="post-metadata">

**Author:** ![haller](https://avatars.discourse-cdn.com/v4/letter/h/53a042/32.png) [@haller](https://forums.creativeclouddeveloper.com/u/haller)\
**Post date:** [January 8, 2024, 3:32pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-select-all-layers/7327/3 "2024-01-08T15:32:58Z")

</div>

Welcome meatloaf\_18  
Since you’re just starting out, my advice is to use some methods to use UXP,  
to get started you can use the actions panel,  
select the action you want to convert, go to the 3 lines on the right and select copy as javascript and paste it into the document.

Second option  
go to the plugin menu at the bottom and you will find devetolement  
and select  
record action notification  
or  
record action command.

Another option, and use alchemist  
a powerful tool created by Jarda, a person of great intelligence and availability.

anyway this should do what you ask.

```auto

SELECT_LAYER()

async function Layer_Unic() {
    let result;
    let psAction = require("photoshop").action;

    let command = [
        {"_obj":"select","_target":[{"_enum":"ordinal","_ref":"layer","_value":"back"}],"layerID":[1],"makeVisible":false},
        {"_obj":"set","_target":[{"_enum":"ordinal","_ref":"layer","_value":"targetEnum"}],"to":{"_obj":"layer","name":"Sfondo"}},
        {"_obj":"select","_target":[{"_enum":"ordinal","_ref":"layer","_value":"front"}],"layerID":[5],"makeVisible":false},
        {"_obj":"select","_target":[{"_name":"Sfondo","_ref":"layer"}],"layerID":[1,16,17,18,19,20,21],"makeVisible":false,"selectionModifier":{"_enum":"selectionModifierType","_value":"addToSelectionContinuous"}},
        {"_obj":"newPlacedLayer"}
    ];
    result = await psAction.batchPlay(command, {});
}

async function SELECT_LAYER() {
    await require("photoshop").core.executeAsModal(Layer_Unic, {"commandName": "Action Commands"});
}

```
