5 Replies Latest reply on Feb 24, 2017 3:43 PM by Chuck Uebele

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

    knsa48112119 Level 1

      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)

        • 1. Re: Select current layer on all open documents (by layer name)
          Chuck Uebele Adobe Community Professional & MVP

          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[i];
              try{
                  app.activeDocument.activeLayer = app.activeDocument.layers.getByName (layerName);
                  }
              catch(e){}
              }
          
          2 people found this helpful
          • 2. Re: Select current layer on all open documents (by layer name)
            knsa48112119 Level 1

            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

            • 3. Re: Select current layer on all open documents (by layer name)
              JJMack Most Valuable Participant

              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.

              1 person found this helpful
              • 4. Re: Select current layer on all open documents (by layer name)
                knsa48112119 Level 1

                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[i]; 
                7.     try
                8.         app.activeDocument.activeLayer = app.activeDocument.layers.getByName (layerName); 
                9.         } 
                10.     catch(e){} 
                11.     } 
                • 5. Re: Select current layer on all open documents (by layer name)
                  Chuck Uebele Adobe Community Professional & MVP

                  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.

                  1 person found this helpful