Getbyname not working

I’m sure I’m doing something wrong but give these docs ( I assumed that I could just do this to query for a layer:


But it don’t work. Any ideas?

What else are you doing in your code? What are you expecting to happen when you run that code?

var test = app.activeDocument.layers.getByName('cool-name');

You could do something like:

test.selected = true;

But you need to be in exmodal state for that.

Oh, I didn’t realize it had to be inside an exmodal. So some stuff works outside and some only inside of exmodal? Why? And what is the exmodal?

To get something, you don’t need to be in modal state. Only to change something. So getByName() shouldn’t be an issue. But setting layer as selected - is a state change and needs to be executed in modal state