5 Replies Latest reply on Jun 9, 2013 4:51 PM by alfonsodev

    Iterate over all document layers applescript

    alfonsodev

      Hi,I have experience as programmer but not in applescript or photoshop scritpting,

      Basically I want to apply some actions to layers, but only to those layers that are named ending in '-changeMe' e.g ( 'Layer 1-changeMe', 'Background-changeMe')

       

      I'm trying to convert the pseudocode below to applescript

       

      foreach layer in CurrentDocument.layers

         if layer.name contains '-changeMe'

             do something

         end if

      end foreach

       

      In the pseudocode above I'm inveting the notation, but I hoppe you get the idea.

      it's posible?

      Thanks!

        • 1. Re: Iterate over all document layers applescript
          c.pfaffenbichler Level 9

          Would you be willing to use JavaScript instead?

          I think at least one of the regulars in this Forum is AppleScript savvy, but most people seem to avoid it for Photoshop Scripting purposes.

          • 2. Re: Iterate over all document layers applescript
            alfonsodev Level 1

            Yes, I love javascript, but I'm wondering if it's posible to launch javascript  actions from actionscript.  Because I want to have some actions integrated at the OS level, to have the posibility for example to right click on a folder or file and launch the script from there, passing the folder path or file as an argument.

            Not sure if I can call javascript from applescript.

            Apart of that I'm intresting to see javascript solutions to the same problem, I may still change my mind while practicing.

            • 3. Re: Iterate over all document layers applescript
              Muppet Mark Level 5

              Yes you can call any JavaScript syntax including Action Manager syntax from AppleScript… You pass the command a string or file to the JS and it also takes arguments…

              1 person found this helpful
              • 4. Re: Iterate over all document layers applescript
                pixxxel schubser MVP & Adobe Community Professional

                I can't help you with AppleScript.

                But this JavaScript works.

                 

                // FindStringInLayersName.jsx
                // http://forums.adobe.com/thread/1227665?tstart=0
                // find layers which have "-changeMe" in the name
                
                var theLayers = app.activeDocument.layers;
                var LayersName, result;
                var searchString = /[-]changeMe/;
                
                for (i=0; i<theLayers.length; i++) {
                    LayersName = theLayers[i].name;
                    result = LayersName.search(searchString);
                
                    if (result != -1) {
                        alert("Found in layer: "+LayersName);
                        // or do something else
                    }
                }
                

                 

                Perhaps someone else can translate this.

                 

                Good luck

                1 person found this helpful
                • 5. Re: Iterate over all document layers applescript
                  alfonsodev Level 1

                  Thanks guys for the help, I finally manage to mix applescript and javascript, simply awesome.

                   

                  --target Photoshop CS6

                  tell application "Adobe Photoshop CS6"

                  do javascript "

                             var theLayers = app.activeDocument.layers;

                  var LayersName, result;

                  var searchString = /[-]changeMe/;

                   

                  for (i=0; i<theLayers.length; i++) {

                      LayersName = theLayers[i].name;

                      result = LayersName.search(searchString);

                   

                      if (result != -1) {

                          alert('Found in layer: '+LayersName);

                          // or do something else

                      }

                  }

                            "

                  end tell