5 Replies Latest reply on Oct 15, 2015 10:27 PM by Qwertyfly...

    Rename active document while saving

    beto correa Level 1

      Hi

       

      Is there any possibility through script to rename the active document while saving?

       

      For example:

       

      Current: 124efg.ai

       

      To save and exit: 124efg_X.ai.

       

      Is it possible? Can someone help me?

        • 1. Re: Rename active document while saving
          Larry G. Schneider Adobe Community Professional & MVP

          Beto, take a look at the Java Script sample files. There's a get new name function you can use. Here's an example

           

          /*********************************************************

           

          getNewName: Function to get the new file name. The primary

          name is the same as the source file.

           

          **********************************************************/

           

          function getNewName()

          {

              var ext, docName, newName, saveInFile, docName;

              docName = sourceDoc.name;

              ext = '.pdf'; // new extension for pdf file

              newName = "";

                 

              for ( var i = 0 ; docName[i] != "." ; i++ )

              {

                  newName += docName[i];

              }

              newName += ext; // full pdf name of the file

             

              // Create a file object to save the pdf

              saveInFile = new File( destFolder + '/' + newName );

             

           

              return saveInFile;

          }

          • 2. Re: Rename active document while saving
            pixxxel schubser Level 5

            Hi beto correa,

            you can do e.g. something like this:

            var theName = app.activeDocument.name;
            theName = theName.replace (/\.ai/,'_X.ai'); // you can use this variable for saving
            
            

             

            Have fun

             

            • 3. Re: Rename active document while saving
              beto correa Level 1

              Hi Thanks so much

               

              When you run the script in the plugin script bay name in the footer changes but the document name remains the same and when I try to find the renamed (_x) I can not find. I did something wrong or is it still need to edit and finalize the script?

              mostra.jpg

              • 4. Re: Rename active document while saving
                pixxxel schubser Level 5

                You can:

                - save as the opened file as a new file with the new name (you get a copy with the new name) or

                - rename the closed file

                 

                IMHO it is not possible to save (and rename) an opened file at once.

                • 5. Re: Rename active document while saving
                  Qwertyfly... Level 4

                  try this.

                  // here is the string to add to the file name
                  var MyAddition = "_X";
                  //
                  var doc = app.activeDocument;
                  var docName = String(doc.fullName);
                  var newDocName = docName.replace(docName.substr(docName.lastIndexOf('.')),MyAddition+docName.substr(docName.lastIndexOf('.')));
                  doc.save();
                  doc.close();
                  File(docName).rename(newDocName);
                  app.open(File(newDocName));