How to select all layers

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!

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”});

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
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.


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

    let command = [
    result = await psAction.batchPlay(command, {});

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