9 Replies Latest reply on Apr 10, 2014 7:45 AM by c.pfaffenbichler

    Auto Rename Path

    malleng

      Hello guys,

       

      i have to rename, and check the correct path names for more then 3000 images. In most cases, the path name should already have the right name.

      After some google research, i found this script:

       

       

      if (app.documents.length > 0) {

       

      if (app.activeDocument.pathItems.length > 0) {

       

      app.activeDocument.pathItems[0].name = "Pathname "

       

      }

       

      };

       

       

      it seems to be exactly what i'm looking for.

       

      But now i got the problem, that every time the path name of the current document is already "pathname",

      a pop up opens in Photoshop and asks me, if i want to rename the path.

      Since pressing 1500 times on "enter" is not an option for me and i dont want to use this tool:

      http://seminarjunkiesanonymous.com.au/wp-content/uploads/2011/04/homers_bird.jpg

      i hope that someone of you  can help me.

       

       

      Thank you very much!

        • 1. Re: Auto Rename Path
          c.pfaffenbichler Level 9

          You can wrap the line that renames in another if-clause where you check the name is different from what you want to change it to.

          if (app.activeDocument.pathItems[0].name != "Pathname ") {

          app.activeDocument.pathItems[0].name = "Pathname "

          }

          1 person found this helpful
          • 2. Re: Auto Rename Path
            malleng Level 1

            Hey, thank you very much for your answer!

            since i'm realy not into scripting:

             

            should it look like this now?

             

            if (app.documents.length > 0) {

             

            if (app.activeDocument.pathItems.length > 0) {

            app.activeDocument.pathItems[0].name = "any"

             

            if (app.activeDocument.pathItems[0].name != "any") {

                app.activeDocument.pathItems[0].name = "any"

            }

                }

             

            };

             

             

             

            + is it also possible, to auto import files from a specific folder, change the path name and save the file in another folder?

             

            Thank you very much for your help!

            • 3. Re: Auto Rename Path
              c.pfaffenbichler Level 9

              No.

              Now you have the line twice.

              1 person found this helpful
              • 4. Re: Auto Rename Path
                Chuck Uebele Adobe Community Professional & MVP

                You could make an action to run your script, then use the batch command to open a folder of files, run your action/script then save to a new folder.  And as c.pfaffenbicher said, you've got the same line twice.  Delete the third line in you above example.

                1 person found this helpful
                • 5. Re: Auto Rename Path
                  malleng Level 1

                  Thank you very much guys.

                  I found a solution now.

                   

                   

                  var selFolder = Folder.selectDialog( 'Location of images to process...' );

                   

                  var files = selFolder.getFiles ( /\.jpg$/i );// may need to edit for different formats

                   

                  var newPathName = prompt ("Pfadnamen eintragen", 'Proll', "Pfad 1")  

                   

                     for(var f = 0; f < files.length; f++ )

                   

                     {

                   

                        var doc = app.open( files[f] );

                   

                        var numberOfPaths = doc.pathItems.length;

                   

                        for( var p = 0; p < numberOfPaths; p++ )

                   

                           {

                   

                           if( doc.pathItems[0].kind == PathKind.NORMALPATH && newPathName !=  doc.pathItems[0].name ) doc.pathItems[0].name =  newPathName;

                   

                           }

                         

                   

                     doc.close(SaveOptions.SAVECHANGES);

                    

                    

                   

                     }

                   

                   

                  This will select the normalpath on first position and rename it. 

                   

                  Thanks!

                  • 6. Re: Auto Rename Path
                    Chuck Uebele Adobe Community Professional & MVP

                    If you just want to change the first path, you don't need the for loop.  In fact, the way it's written now, the loop does nothing.  Normally, if you use a loop like this you would have the "p" replace the "0" in the array brackets, so that as the loop progresses, it works on the next obect in the array - in this case the paths.

                    • 7. Re: Auto Rename Path
                      malleng Level 1

                      The problem was, that some of the images i had to edit, had more then 1 path. And sometimes, some of that existing paths were already named the way i had to name the 1. Path.

                      However, when i was using [p] instead of [0] (wich i did first), i had to accept the name change in those cases by pressing enter and received an error message after.

                      (path name was already given)

                       

                      After i used "0" instead of "p" it worked.

                      But like i already said, i got like 1% clue of what i actually did here. Im just glad it worked somehow.

                       

                      If you are enthusiastic enough to teach me why i had that problem, i'm willing to learn.

                       

                      Thank you!

                      • 8. Re: Auto Rename Path
                        Chuck Uebele Adobe Community Professional & MVP

                        I'm still unsure about what exactly you want to do.  Do you want just the very first path name renamed to the one you selected?  Here are some changes I would make to the script:

                         

                        Turn off dialogs.

                        Add PSD save options - I'm assuming you want them saved as psd.

                        Add dialog to select a save to folder

                        Get rid of second loop that goes through the paths.

                        Add a try/catch block so you don't get error messages

                        Add a save as to save the file to a new location.

                        Change SAVECHANGES to DONOTSAVECHANGES to get rid of extra dialog that you don't need.

                         

                         

                        #target photoshop

                         

                        app.displayDialogs = DialogModes.NO;

                        var psdOptions = new PhotoshopSaveOptions()

                        psdOptions.layers = true

                               

                        var selFolder = Folder.selectDialog( 'Location of images to process...' );

                         

                        var saveFolder = Folder.selectDialog('Path for save folder');

                         

                        var files = selFolder.getFiles ( /\.jpg$/i );// may need to edit for different formats;

                        var newPathName = prompt ("Pfadnamen eintragen", 'Proll', "Pfad 1"); 

                         

                           for(var f = 0; f < files.length; f++ ){

                              var doc = app.open( files[f] );

                              var numberOfPaths = doc.pathItems.length;

                              try{

                                 if( doc.pathItems[0].kind == PathKind.NORMALPATH && newPathName !=  doc.pathItems[0].name ) doc.pathItems[0].name =  newPathName;

                              }//end try

                              catch(e){}

                                 }//end for loop

                           doc.saveAs (new File(saveFolder +'/' + doc.name), psdOptions)

                           doc.close(SaveOptions.DONOTSAVECHANGES);

                           }

                        1 person found this helpful
                        • 9. Re: Auto Rename Path
                          c.pfaffenbichler Level 9

                          Ah, I had overlooked that all PathItem’s names have to be taken into consideration.