12 Replies Latest reply on Feb 26, 2015 6:36 AM by Laubender

    Save as copy

      Is there a way to script save as copy. I want to preserve the open file in it's current location and manually perform save as there, would like to use save as copy on a setInterval so that once the first copy is saved subsequent copies will save in the background; not requiring user involvement.

      I have the following for save as but I can't find save as copy. Should it be something like this or something else altogether?

      Thanks!

      if(app.activeDocument.modified == true){"
      app.activeDocument.save();
      }
        • 1. Re: Save as copy
          Hi,

          This is how to Save As

          app.activeDocument.save(new File(yourNewFileName));

          But I guess we are both looking for Save A Copy wherein the old document stays opened. Unlike the code above, the old document is closed and the new file opened.

          Can anybody help?

          Thanks!
          • 2. Re: Save as copy
            Level 1
            The closest you can come is to save twice, first to the "copy" and then back over the original. But this does mean that you lose the undo queue. If that's OK, then you're set. It also only works with documents that have previously been saved.

            Dave
            • 3. Re: Save as copy
              Kasyan Servetsky Level 5
              var myDoc = app.activeDocument;
              
              myDoc.save();
              var myFile = myDoc.fullName;
              var myDate = new Date;
              var mySuffix = "_Backup_" + myDate.getDate() + "_" + myDate.getMonth() +  "_" + myDate.getHours() + "-" + myDate.getMinutes() + "-" + myDate.getSeconds() +".indd"
              var myBaseName = myDoc.fullName.fsName.match(/(.*)\.[^\.]+$/)[1] ;
              var myNewFile = new File(myBaseName + mySuffix);
              myFile.copy(myNewFile);
              • 4. Re: Save as copy
                Level 1
                Hi guys,

                Thanks for sharing your knowledge. It didn't help much with what I'm doing because I have to do several UNDO's and I don't think reverting would help since the file is saved before copying it to another file.

                I was hoping you guys know how to close dialog boxes like missing fonts and missing link after opening the file. My script below has a bit of a problem because the missing fonts dialog box prevents the script from continuing.

                myDocument.save(File(myPath+"/"+mySplit+j+".indd"));
                app.activeDocument.close();
                app.open(File(myFilename));

                Appreciate if you could help. Thanks a lot.
                • 5. Re: Save as copy
                  Muthuraj Durairaj Level 1

                  Hi Kasyan,

                   

                  Thanks for the save as copy script. It is duplicating the existing INDD file with the "backup" name. It is working fine. I just want to perform a menu action File > Save a Copy, so that the final file size would get reduced. Is there any way to perform this action thru javascript? My advance thanks for your help.

                   

                  Regards,

                  Muthuraj. D

                  • 6. Re: Save as copy
                    Kasyan Servetsky Level 5

                    I just want to perform a menu action File > Save a Copy, so that the final file size would get reduced. Is there any way to perform this action thru javascript?

                    Here is how to resave the active document with the same name (and reduce file size)

                    var myDoc = app.activeDocument;
                    var myFile = myDoc.fullName;
                    myDoc.save(myFile);
                    

                     

                    To save it with a different name change this line like so:

                    var myFile = new File(myDoc.fullName + " copy");

                     

                    BTW, I wrote a script that batch resaves InDesign documents.

                     

                    Kasyan

                    • 7. Re: Save as copy
                      sarvod1219

                      Sir, Your script worked fine.  Suppose I am working in f:\xyz folder.  I want to save a copy in g:\temp folder.  I just modified your script

                       

                      var filepath = /g/temp/

                      myFile.copy(filepath myNewFile)

                       

                      I am getting error message ) expected.  How do i save the copy to another folder.  Also, is it possible to auto save the file every 30 to 60 seconds.

                       

                      Thanks

                      • 8. Re: Save as copy
                        Laubender Adobe Community Professional & MVP

                        @sarvod – it's the syntax of your variable filepath that is wrong.

                        You can find out the right syntax, if you use the following snippet and navigate to your folder:

                         

                        var myFolderPath = Folder.selectDialog();
                        alert("myFolderPath:"+"\r"+"\""+myFolderPath+"\"");
                        

                         

                         

                        Uwe

                        • 9. Re: Save as copy
                          sarvod1219 Level 1

                          i got the right syntax.  However, when I save i do not want a save as dialog box.  It should automatically copy the file to the folder specified say for example d:\temp\

                          • 10. Re: Save as copy
                            Laubender Adobe Community Professional & MVP

                            Are we talking ExtendScript/JavaScript here?

                             

                            Uwe

                            • 11. Re: Save as copy
                              sarvod1219 Level 1

                              Java Script.  Sorry for not being clear.  Here is the complete script which I got.

                               

                              var myDoc = app.activeDocument;

                              myDoc.save();

                              var myFile = myDoc.fullName;

                              var myDate = new Date;

                              var mySuffix = "_Backup_" + myDate.getDate() + "_" + myDate.getMonth() + "_" + myDate.getHours() + "-" + myDate.getMinutes() + "-" + myDate.getSeconds() +".indd"

                              var myBaseName = myDoc.fullName.fsName.match(/(.*)\.[^\.]+$/)[1] ;

                              var myNewFile = new File(myBaseName + mySuffix);

                              var myPathName = "d:/Temp";

                              myFile.copy(myNewFile);

                               

                              This script saves the current file and makes a copy in the current location.  I am trying to alter the last line "my File.copy(myNewFile);  Instead of copying in the current location, the file should be copied to another location say d:\temp

                               

                              Thanks for your replay

                              • 12. Re: Save as copy
                                Laubender Adobe Community Professional & MVP

                                In that code you are doing nothing with your variable myPathName.

                                myPathName would be the argument of the copy() method, I think…

                                 

                                And: I think, could be wrong, you should add a "/" to the value of myPathName like this:

                                 

                                var myPathName = "d:/Temp/";
                                

                                 

                                myDoc.fullName should qualify as a File object, if it is saved with a name and not untitled.

                                 

                                myDoc.fullName.copy(myPathName);
                                

                                 

                                Did not try it, but it should work for you.

                                Ok. This is not changing file name of the copied document.

                                 

                                Perhaps you could provide one:

                                 

                                myDoc.fullName.copy(myPathName+myNewBaseName+".indd");
                                

                                 

                                or if that doesn't do it:

                                 

                                myDoc.fullName.copy(File(myPathName+myNewName+".indd"));
                                

                                 

                                Or you can attempt to change the name of the copied file.

                                copy() will not return the copied file. It will return a bool value, true or false (in case it would not work).

                                 

                                See here in Jongware's DOM documentation for Core JavaScript Classes:

                                CS3 JS: File

                                 

                                E.g. File has a method: rename()

                                Details:

                                CS3 JS: File

                                 

                                Uwe