14 Replies Latest reply on Jun 9, 2012 9:20 AM by Muppet Mark

    Script to Sort Images with/without Clipping Paths?

    Andymc7 Level 1

      I've searched for a while and can't find a script that will sort a folder of images into two new folders that contain images with and without clipping paths. Anyone have or know of a script that will do this for me? I'd would greatly appreciate it. W7, PS CS5 32 and 64 bit.

       

      Thanks in advance!

       

      Andy

        • 1. Re: Script to Sort Images with/without Clipping Paths?
          Paul Riggott Level 6

          Hi Andy, Mike has a function to check for clipping groups but requires the file to be open...

           

           

          //////////////////////////////////////////////////////////////////////////////
          // Function: clippingPathIndex
          // Description: Gets the index of the activeDocument's clipping path
          // Usage: clippingPathIndex() 
          // Input: None
          // Return: Index as Integer. -1 if there is no clipping path
          ///////////////////////////////////////////////////////////////////////////////
          function clippingPathIndex(){
               var ref = new ActionReference();
                    ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
               var desc = executeActionGet( ref );
               var clippingPath =  desc.getObjectValue(charIDToTypeID("Clpg"));
               return  clippingPath.getInteger(charIDToTypeID("ClpI" )); 
          }
          
          
           

           

          I think it should be possible to check the files without opening them using Bridge, looking at the Photoshop File Format it says....

           

           

           

          If the file contains a resource of type 8BIM with an ID of 2999, then this resource contains a Pascal-style string containing the
          name of the clipping path to use with this image when saving it as an EPS file. 4 byte fixed value for flatness and 2 byte fill rule.
          0 = same fill rule, 1 = even odd fill rule, 2 = non zero winding fill rule. The fill rule is ignored by Photoshop.
          
          

           

          I will see if I have time today to put something together for you.

          • 2. Re: Script to Sort Images with/without Clipping Paths?
            Paul Riggott Level 6

            Ok, hopefully this should work
            Open Bridge
            Edit - Preferences - Startup Scripts and click the "Reveal My Startup Scripts" button.
            Save the script into this folder and restart Bridge.
            You will now have an option under the Tools menu "Sort Clipping Paths"

            To use navigate to the folder you want to sort and run the script.
            It will sort the files into two folders off the selected folder "hasClip" and "noClip"

             

             

            #target bridge
             if( BridgeTalk.appName == "bridge" ) {  
            clipPaths = MenuElement.create("command", "Sort Clipping Paths", "at the end of Tools","clipping");
            }
            clipPaths.onSelect = function () { 
            app.document.deselectAll();
            var thumbs = app.document.getSelection("psd, tif, jpg, eps");
            var noClip = new Folder(app.document.presentationPath+ '/noClip');
            var hasClip = new Folder(app.document.presentationPath+ '/hasClip');
            if(!noClip.exists)  noClip.create();
            if(!hasClip.exists)  hasClip.create();
            for(var a in thumbs){
            var tempFile = thumbs[a].spec;
            var Path = false;
            var Clip = false;
            tempFile.encoding='BINARY';
            tempFile.open('r');
            var str= tempFile.read();
            tempFile.close();
            var pathTag = '8BIM\x07\xd0';
            var clippingPathTag = '8BIM\x0b\xb7';
            var tagPos =str.match(pathTag);
            if(tagPos){
                Path = true;
                tagPos =str.match(clippingPathTag);
                if(tagPos){
                    Clip = true;
                    }   
            }
            str = null;
            if(!Path) thumbs[a].moveTo(noClip);
            if(Path && !Clip) thumbs[a].moveTo(noClip);
            if(Path && Clip)  thumbs[a].moveTo(hasClip);
            }
            };
            
            
             
            • 3. Re: Script to Sort Images with/without Clipping Paths?
              Andymc7 Level 1

              Hey Paul, thanks so much for the script but I'm afraid it didn't work as expected. After it's ran, both the hasClip and noClip folders contain files that have clipping paths.

               

              Also, is there a way to allow the script to check for ANY path (clipping or workpath) a file may contain? As you may suspect I have the task of processing many images that have been poorly processed and optimized, and want to end up with one folder of either clipping path jpegs or neatly trimmed LZW compression Tiffs. I'm dealing with a wide variety of formats, color spaces/profiles, sizes, etc..  (The files I tested with your script are psd's)

               

              Thanks again,

               

              Andy

              • 4. Re: Script to Sort Images with/without Clipping Paths?
                Muppet Mark Level 5

                I have 3 flavors here… I haven't looked at them in a while… Work Path I did not do back then didn't know how to find that…

                 

                http://ps-scripts.com/bb/viewtopic.php?f=19&t=4267&sid=e822e0808e8f68042b721e7534692233

                1 person found this helpful
                • 5. Re: Script to Sort Images with/without Clipping Paths?
                  Paul Riggott Level 6

                  Mark has done a lot more work on these than I have so it would be worth while having a look at them.

                  Mark does your scripts find grouped layers?

                   

                  The script as it stands should find clipping paths but not grouped layers.

                   

                  I have altered the script to split the files into three folders noPath, hasPath and hasClip.

                   

                   

                  #target bridge
                   if( BridgeTalk.appName == "bridge" ) {  
                  clipPaths = MenuElement.create("command", "Sort Clipping Paths", "at the end of Tools","clipping");
                  }
                  clipPaths.onSelect = function () { 
                  app.document.deselectAll();
                  var thumbs = app.document.getSelection("psd, tif, jpg, eps");
                  var noPath = new Folder(app.document.presentationPath+ '/noPath');
                  var hasPath = new Folder(app.document.presentationPath+ '/hasPath');
                  var hasClip = new Folder(app.document.presentationPath+ '/hasClip');
                  if(!noPath.exists)  noPath.create();
                  if(!hasClip.exists)  hasClip.create();
                  if(!hasPath.exists)  hasPath.create();
                  for(var a in thumbs){
                  var tempFile = thumbs[a].spec;
                  var Path = false;
                  var Clip = false;
                  tempFile.encoding='BINARY';
                  tempFile.open('r');
                  var str= tempFile.read();
                  tempFile.close();
                  var pathTag = '8BIM\x07\xd0';
                  var clippingPathTag = '8BIM\x0b\xb7';
                  var tagPos =str.match(pathTag);
                  if(tagPos){
                      Path = true;
                      tagPos =str.match(clippingPathTag);
                      if(tagPos){
                          Clip = true;
                          }   
                  }
                  str = null;
                  if(!Path) thumbs[a].moveTo(noPath);
                  if(Path && Clip)  thumbs[a].moveTo(hasClip);
                  if(Path && !Clip) thumbs[a].moveTo(hasPath);
                  }
                  };
                  
                  
                  • 6. Re: Script to Sort Images with/without Clipping Paths?
                    Andymc7 Level 1

                    Awesome, thanks!

                     

                    Now I've come across psd's that for some reason were saved with no transparency OR path, and some with transparency.. ugh.. so if you guys would be so kind to point me to a script that may check for transparency in an image and sort them, that would be great too. If not, no biggie, you've already helped a bunch.

                     

                    Much thanks!

                     

                     

                    Andy

                    • 7. Re: Script to Sort Images with/without Clipping Paths?
                      Muppet Mark Level 5

                      I think I went another way for *.eps when I did it… Paul the reasons for a 3 way spil for me are…

                       

                      Clipping Path will default to cut-out in InDesign

                      Saved Paths I can manually select from to cut-out in InDesign

                      No Paths will need sending out to process

                       

                      Work Path would need to be saved to regular Path for InDesign to see it…

                       

                      This is regular stuff for page layout ID or AI.

                      • 8. Re: Script to Sort Images with/without Clipping Paths?
                        Paul Riggott Level 6

                        Thanks Mark, I have the same problem with this script a Work Path is not found unless it has been saved.

                        Grouped layers are not classified as paths either, only paths saved as Clipping Path.

                        • 9. Re: Script to Sort Images with/without Clipping Paths?
                          Muppet Mark Level 5

                          On the PC exiftool may help you with that…

                          • 10. Re: Script to Sort Images with/without Clipping Paths?
                            Muppet Mark Level 5

                            Paul, I got the PS file spec after doing these… Most was based on what I had found with AppleScript some years back… Im have the feeling work path has it's own tag…

                            • 11. Re: Script to Sort Images with/without Clipping Paths?
                              Paul Riggott Level 6

                              Yes you are right yet again Mark, I have found the tag. It's 0x0401

                               

                              Here is the corrected script that now supports unsaved Work Paths.

                               

                               

                              #target bridge
                               if( BridgeTalk.appName == "bridge" ) {  
                              clipPaths = MenuElement.create("command", "Sort Clipping Paths", "at the end of Tools","clipping");
                              }
                              clipPaths.onSelect = function () { 
                              app.document.deselectAll();
                              var thumbs = app.document.getSelection("psd, tif, jpg, eps");
                              var noPath = new Folder(app.document.presentationPath+ '/noPath');
                              var hasPath = new Folder(app.document.presentationPath+ '/hasPath');
                              var hasClip = new Folder(app.document.presentationPath+ '/hasClip');
                              if(!noPath.exists)  noPath.create();
                              if(!hasClip.exists)  hasClip.create();
                              if(!hasPath.exists)  hasPath.create();
                              for(var a in thumbs){
                              var tempFile = thumbs[a].spec;
                              var Path = false;
                              var Clip = false;
                              tempFile.encoding='BINARY';
                              tempFile.open('r');
                              var str= tempFile.read();
                              tempFile.close();
                              var pathTag = '8BIM\x07\xd0';
                              var clippingPathTag = '8BIM\x0b\xb7';
                              var workPath = '8BIM\x04\x01';
                              var tagPos =str.match(pathTag);
                              if(tagPos){
                                  Path = true;
                                  tagPos =str.match(clippingPathTag);
                                  if(tagPos){
                                      Clip = true;
                                      }   
                              }
                              if(!Path){
                                  if(str.match(workPath)) Path = true;
                                  }
                              str = null;
                              if(!Path) thumbs[a].moveTo(noPath);
                              if(Path && Clip)  thumbs[a].moveTo(hasClip);
                              if(Path && !Clip) thumbs[a].moveTo(hasPath);
                              }
                              };
                              
                              
                               
                              1 person found this helpful
                              • 12. Re: Script to Sort Images with/without Clipping Paths?
                                Muppet Mark Level 5

                                Paul, up until just now I have had no luck with reading files with encoding set to binary… It locks up my toolkit after just 1 run… I have to quit the ESTK and launch each time… This bothered me no end and I gave up. Today I wrap the exact same sytax in function and it work over and over no locking… What have I done to cause this issue and how do I resolve it?

                                • 13. Re: Script to Sort Images with/without Clipping Paths?
                                  Paul Riggott Level 6

                                  Good question Mark, and I wish I knew the answer. Mine locks up all the time with CS5/CS6 but I find I can run them ok with CS3 ESTK. I don't even bother using CS4 ESTK as that is just a nightmare.

                                  I will have to try wrapping in a function and see if it helps.

                                  • 14. Re: Script to Sort Images with/without Clipping Paths?
                                    Muppet Mark Level 5

                                    Argh… and I was just presuming toolkit always right n me the muppet… it might be a bit of both then… I tend to wrap everything up in functions once I've got going… but this was almost a non-starter for me… Thought it may be some global clobbering of which I know close to nothing… Live n learn…