How to get layer name

Hello everyone,
Does anyone know the batchPlay code to get the layer name?
This is the code I use now:
It can get the layer name, but when used with the slider, it is too slow, so I need to run better batchPlay code.

I found the previous code,how to convert it to uxp code

function getLayerName (theIndex) {

var ref = new ActionReference();

ref.putIndex ( charIDToTypeID( "Lyr " ), theIndex);

var layerDesc = executeActionGet(ref);

var theName = layerDesc.getString (stringIDToTypeID ("name"));

return theName


You can use the following batchPlay to retrieve the current active layer:

const action = window.require('photoshop').action;

let activeLayerData = await action.batchPlay([{
    "_obj": "get",
    "_target": [{ "_ref": "layer", "_enum": "ordinal", "_value": "targetEnum" }],
    "_options": {
        "dialogOptions": "dontDisplay"
}], { modalBehavior: "execute" });

Thank you very much. It really works.

1 Like