Skip to main content
knsa48112119
Participant
February 23, 2017
Answered

Select current layer on all open documents (by layer name)

  • February 23, 2017
  • 1 reply
  • 1497 views

I need a way to select the same layer on all open documents.  For example, I would like to select the layer 'Main' on my active document, run the script and have the 'Main' layer selected on the rest of the documents (so I can tab through them quickly and edit).  I always use the same layer names if that helps.  'Main', 'Curves 1', 'Shadow' (folder with mask), and 'Edits'. 

I'm currently doing this using actions but it's messy.  I used to have a script that could do this but I haven't been able to find it online after endless searching. 

(PS 2017)

This topic has been closed for replies.
Correct answer Chuck Uebele

You can try this. just put in the layer name in line 2, and it is case sensitive.

#target photoshop

var layerName = 'Main';

var num = app.documents.length;

for(var i = 0;i<num;i++){

    app.activeDocument = app.documents;

    try{

        app.activeDocument.activeLayer = app.activeDocument.layers.getByName (layerName);

        }

    catch(e){}

    }

1 reply

Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
February 23, 2017

You can try this. just put in the layer name in line 2, and it is case sensitive.

#target photoshop

var layerName = 'Main';

var num = app.documents.length;

for(var i = 0;i<num;i++){

    app.activeDocument = app.documents;

    try{

        app.activeDocument.activeLayer = app.activeDocument.layers.getByName (layerName);

        }

    catch(e){}

    }

knsa48112119
Participant
February 24, 2017

Thanks for your help with this.  This does select the named layer on all of my open documents, and it's way faster than what I had been doing.  Very handy!  One thing I'm trying to avoid is using multiple scripts/actions to make these selections.  Ideally I'd like to be able to select any layer on the active window and with one shortcut/action have it selected on the rest of the documents.  I wasn't sure if using the 4 named layers would be easier than using some other (variable?).  i'm going to try fiddling with what you gave me

JJMack
Community Expert
Community Expert
February 24, 2017

The script could be written to use the current target layer name.  You would target the layer in the active document and then use you shortcut for the script. The script would get the active document targeted layer name and would try target a layer with that name in the other open documents.  One layer with the name would be targeted would be targeted if one exist.  Layer name need not be unique so all layer with the name may not be targeted.   Just change the script to use the active layer name.

JJMack