Select text layers didn't work

Select all text layers didn’t work in my script!
This discussion talks about the subject, but I don’t understand.

Can someone explain me better where to add constants to work correctly. Thanks

const app = window.require("photoshop").app;

const layers = await app.activeDocument.layers;
try {
	// Percorre todas as camadas
	for (var i = 0; i < layers.length; i++) {
		var layer = layers[i];
		if (layer.kind === LayerKind.TEXT) {
			layer.selected = true;
		}
	}
}
 catch(e){console.log(e)}

erro: ReferenceError: LayerKind is not defined

Now it worked!

const constants = require("photoshop").constants
const layers = await app.activeDocument.layers;

for (var i = 0; i < layers.length; i++) {
    var layer = layers[i];
    if (layer.kind === constants.LayerKind.TEXT) {
    layer.selected = true;
  }
}

I think await can be omitted while getting the document’s layers.

1 Like