Sure, layer descriptors have a property called itemIndex
, that you can get like any other property. You can reference a layer by name (instead of referencing the active layer or a layer by id) via { _ref: 'layer', _name }
which u pass to the _target
array:
const idx = photoshop.action.batchPlay([
{
_obj: 'get',
_target: [{ _property: 'itemIndex' }, { _ref: 'layer', _name: *name* }],
},
], { synchronousExecution: true })[0]['itemIndex']
Be aware that indices in PS are affected by the document having a background layer or not. To get correct results, you might need to add some logic like here: