9 Replies Latest reply on Dec 13, 2012 2:16 AM by [Jongware]

    How to SAVE the file

    BEGINNER_X Level 3

      Hi All,


      10  indesign files (i.e., Untitled-1, Untitled-2, Untitled-3,...............Untitled-10) are open at the same time.





      Close all the files at the same time and save all the files with their proper naming like Untitled-1, Untitled-2 etc... in some location in my Desktop.



      Lines i am tried from scripting guide are below:


      for(i=app.documents.length; i>0; i--)






      I think where i highlighted bold that one is problem.


      Kindly check and give the solution for me.


      Let me know in case of further clarification.




      Thanks in advance



        • 1. Re: How to SAVE the file
          Vamitul Level 4

          1) http://jongware.mit.edu/idcs5/pc_Document.html#save

          2) http://jongware.mit.edu/idcs5/pc_File.html


          the "~/Desktop/"".indd" is your problem.

          it should be something like: "~/Desktop/"+myDoc.name+".indd".

          however, if the document it is already saved, it will have a problem (for example: "testDoc.indd", after using that save i sugested, will become "testDoc.indd.indd");

          there are some simple fixes, try to find one for yourself first.

          • 2. Re: How to SAVE the file
            BEGINNER_X Level 3

            Hi vamitul,


            I am not able to get the result. While running the script shows the error.


            My question is in my system i opened 10 indesign files like Untitled-1, Untitled-2, Untitled-3 etc....


            Output is i need  Untitled-1, Untitled-2, Untitled-3 etc... want to save as it is like (Untitled-1, Untitled-2, Untitled-3) in some location or in desktop.



            Thanks in advance


            • 3. Re: How to SAVE the file
              Vamitul Level 4

              what error?

              ps. don't know if the path is ok for mac. i'm on windows.

              ps ps. do youself a favor and get some good GENERAL javascript books, and learn the basics.

              • 4. Re: How to SAVE the file
                Muppet Mark Level 5


                #target indesign
                function saveOpenDocs() {
                          var docs, i, saveFile;
                          docs = app.documents;
                          for ( i = docs.length-1; i >= 0; i-- ) {
                                    saveFile = File( Folder.desktop + '/' + app.activeDocument.name + '.indd' );
                                    app.activeDocument.close( SaveOptions.NO, saveFile );
                • 5. Re: How to SAVE the file
                  Anquel Martho

                  Small changes.


                  The value of  the variable docs is app.documents.length, and I would recommend changing the for statement to

                  for(var i = 0; i < docs; i++)...

                  • 6. Re: How to SAVE the file
                    [Jongware] Most Valuable Participant

                    Anquel, Muppet Mark reversed the for..loop because working with "live" arrays doesn't actually work while you are *changing* the array. "app.documents" is such a live array, and closing the document would change it, shifting all documents one place up (much to the confusion of beginners).


                    *However* ... since he doesn't access the documents as "app.document[doc]", but rather simply as "app.activeDocument", this problem is not relevant, and thus it's indeed unnecessary to reverse the loop. But one has to be careful, because a slight change to the script could break this. BEGINNER_X own attempt uses "app.documents.item(i-1)" which *does* need it.


                    An unadressed question lingers: untitled (new) documents do not have a name, and at that point the script will throw an error. To find out if a document has a name, you can inspect its "saved" property (http://jongware.mit.edu/idcs6js/pc_Document.html#saved). If not saved, you should supply a name of your own, such as "File(Folder.desktop + "/Untitled-" + i + ".indd")".

                    • 7. Re: How to SAVE the file
                      Anquel Martho Level 1




                      I tryed accessing app.activeDocument.name and it returned me Untitled1, etc (just tried). But I really remember this issue of being unable to get the name of unsaved documents. Maybe it is necessary to save the document name into a variable and then use it.


                      Well, I just run this code


                      var docName = app.activeDocument.name;

                      var docFile = new File('/c/temp/' + docName + '.indd');

                      app.activeDocument.close(SaveOptions.NO, docFile);


                      and it worked ok.


                      So, what's that beginner_X is doing different?

                      • 8. Re: How to SAVE the file
                        Muppet Mark Level 5

                        Jong, name should be fine or at least it appears to be here…? fullName requires the file be saved… I just get Untitled-[digits]

                        • 9. Re: How to SAVE the file
                          [Jongware] Most Valuable Participant

                          You guys are right!


                          alert (app.activeDocument.name);

                          alert (app.activeDocument.fullName);


                          The first is the name as it appears in the interface, the second is the one I usually use, and this one fails when the document has not yet been saved.


                          But ... if the file is saved, app.activeDocument.name already has an ".indd" extension! So adding ".indd" is not necessary. Anquel's code does not work because it does not save the document under the new name:


                          app.activeDocument.close(SaveOptions.NO, docFile);


                          and if you change it to YES, it's saved with a double file extension.