• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Feb 23, 2017 Feb 23, 2017

Copy link to clipboard

Copied

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)

TOPICS
Actions and scripting

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 23, 2017 Feb 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){}

    }

Votes

Translate

Translate
Adobe
Community Expert ,
Feb 23, 2017 Feb 23, 2017

Copy link to clipboard

Copied

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){}

    }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 24, 2017 Feb 24, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 24, 2017 Feb 24, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 24, 2017 Feb 24, 2017

Copy link to clipboard

Copied

YES!!  It works!!  You guys are amazing.  This did the trick = changing var layerName = 'Main';  to var layerName = app.activeDocument.activeLayer.name;

One minor problem is that it doesn't seem to select the layers if they're inside a group, not a big deal unless you guys know of an easy fix.

  1. #target photoshop 
  2. var layerName = app.activeDocument.activeLayer.name; 
  3. var num = app.documents.length; 
  4.  
  5. for(var i = 0;i<num;i++){ 
  6.     app.activeDocument = app.documents
  7.     try
  8.         app.activeDocument.activeLayer = app.activeDocument.layers.getByName (layerName); 
  9.         } 
  10.     catch(e){} 
  11.     } 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 24, 2017 Feb 24, 2017

Copy link to clipboard

Copied

To get a layer in a group, you would have to loop through the layers and find the layer sets, then search that group, and then loop through that group to check for other groups. A bit slower.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 22, 2022 Apr 22, 2022

Copy link to clipboard

Copied

Can you refine this script to simply list all the currently selected layer sets?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 23, 2022 Apr 23, 2022

Copy link to clipboard

Copied

LATEST
app.activeDocument = app.documents[i];

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines