15 Replies Latest reply on Jun 11, 2014 11:47 PM by hasvi

    How to define log report path

    hasvi Level 1

      Hi,

       

      How to define log report path, below code will generate the report on desktop path, but I want to generate log report on where my indesign file is opened. Can we do this by script. pls help me

       

      This is for opening file:

       

      var path = Folder.selectDialog ("Select folder");

      var files = path.getFiles("*.indt" && "*.indt"),

           myDoc = app.open(new File(files)); 

       

      This is for output file:

       

          var myTextFile = new File("~/Desktop/Log Report.csv")

          myTextFile.open("w")

          myTextFile.write("\nParagraph Style:") 

          myTextFile.write(myMissingParaStyle)

          myTextFile.close();

       

       

      by

      hasvi

        • 1. Re: How to define log report path
          Chinnadk Level 4

          Hi Hasvi,


          Try this,


          var myTextFile = new File(myDoc.filePath + "/LogReport.csv")


          Regards,

          Chinna

          • 2. Re: How to define log report path
            hasvi Level 1

            Hi Chinna,

             

            It shows "Unsaved documents have no path" so want to save my input ("*.indt" && "*.indt")" file as a indd file with "New Indesign" this name, because my input indesign file may be 'indd' or 'indt'. pls help to save my file with name.

             

             

            by

            hasvi

            • 3. Re: How to define log report path
              Chinnadk Level 4

              Try this,

               

              var path = Folder.selectDialog ("Select folder");

              var files = path.getFiles("*.indt" && "*.indt");

              myDoc = app.open(new File(files));

              myDoc.save(new File(path + "/" + "New Indesign.indd"));

              var myTextFile = new File(myDoc.filePath + "/LogReport.csv");

              myTextFile.open("w")

              myTextFile.write("\nParagraph Style:")

              myTextFile.write(myMissingParaStyle)

              myTextFile.close();

               

              Regards,

              Chinna

              • 4. Re: How to define log report path
                hasvi Level 1

                Hi chinna,

                 

                Many thanks. here 'var files = path.getFiles("*.indd" && "*.indt")' this code is correct or not because my folder have 'indt' file it works fine, but my folder have 'indd' file below error is shown,

                1.png

                 

                And one more doubt, your code is shown 'myTextFile.close()' we have another code as like  'myTextFile.close(SaveOptions.SAVECHANGES)' what is the different between these.

                 

                by

                hasvi

                • 5. Re: How to define log report path
                  hasvi Level 1

                  Hi chinna,

                   

                  In below script I have changed library path file only, but its not running.

                   

                  This code is working fine.

                  var doc = app.activeDocument;

                  var library=new File("C:\\Users\\Jayanthi\\Desktop\\test\\Library.indl");//Your library file path.

                  app.open(library);

                  asset = app.libraries[0].assets;

                  for(var i=0;i<asset.length;i++)

                  {

                      try{

                          doc.objectStyles.add({name:asset[i].name});

                          }

                      catch(e){}

                      }

                   

                  This code is running but object style not created

                  function ObjectStyleCreation()

                  {

                  var library = path.getFiles("*.indl");

                  library=File(library);

                   

                  if (!library.exists){   

                  alert("Library File is Missing");

                  exit();}   

                  else

                  {  

                  app.open(library);

                  asset = app.libraries[0].assets;

                  for(var i=0;i<asset.length;i++)

                  {

                      try{

                          doc.objectStyles.add({name:asset[i].name});

                          }

                      catch(e){}

                      }

                  }

                  }

                   

                  by

                  hasvi

                  • 6. Re: How to define log report path
                    Chinnadk Level 4

                    Hi Hasvi,

                     

                    Try the below code. It will ask you to select a file not a folder.

                     

                    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

                    var path = File.openDialog("Select file");

                    myDoc = app.open(new File(path));

                    myDoc.save(new File(path.toString().replace(myDoc.name, "New Indesign.indd")));

                    var myTextFile = new File(myDoc.filePath + "/LogReport.csv");

                    myTextFile.open("w")

                    myTextFile.write("\nParagraph Style:")

                    myTextFile.write(myMissingParaStyle)

                    myTextFile.close();

                    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

                     

                    Regards,

                    Chinna

                    • 7. Re: Re: How to define log report path
                      Chinnadk Level 4

                      Hi Hasvi,

                       

                      Function 'ObjectStyleCreation()' hasn't been called anywhere in your script.

                       

                      Regards,

                      Chinna

                      • 8. Re: How to define log report path
                        hasvi Level 1

                        Hi chinna,

                        This is the full script, its running but object style not created.

                         

                        var path = Folder.selectDialog ("Select folder");

                        var files = path.getFiles("*.indd" && "*.indt"),

                             myDoc = app.open(new File(files));

                        //~     app.activeDocument.save(path.fsName + "\\" + "NewIndesign"+".indd");

                        myDoc.save(new File(path + "/" + "New Indesign.indd"));

                         

                         

                        ObjectStyleCreation();

                         

                         

                        function ObjectStyleCreation()

                        {

                        var library = path.getFiles("*.indl");

                        library=File(library);

                         

                         

                        if (!library.exists){   

                        alert("Library File is Missing");

                        exit();}   

                        else

                        {

                        app.open(library);

                        asset = app.libraries[0].assets;

                        for(var i=0;i<asset.length;i++)

                        {

                            try{

                                doc.objectStyles.add({name:asset[i].name});

                                }

                            catch(e){}

                            }

                        }

                        }

                         

                        by

                        hasvi

                        • 9. Re: How to define log report path
                          Chinnadk Level 4

                          Replace doc with myDoc in the below line.

                           

                          doc.objectStyles.add({name:asset[i].name});

                          • 10. Re: How to define log report path
                            hasvi Level 1

                            thanks chinna,

                             

                            Here my task is we want select folder only, that folder may have 'indd' or 'indt' any one file only that have.

                            here 'var files = path.getFiles("*.indd" && "*.indt")' this code is correct or not because my folder have 'indt' file it works fine, but my folder have 'indd' file not working.

                             

                            by

                            hasvi

                            • 11. Re: How to define log report path
                              Chinnadk Level 4

                              Hi Hasvi,

                               

                              Replace it with : var files = path.getFiles(/\.(indd?|indt?)$/i );

                               

                              Regards,

                              Chinna

                              • 12. Re: How to define log report path
                                hasvi Level 1

                                Superb chinna

                                • 13. Re: How to define log report path
                                  hasvi Level 1

                                  Hi chinna,

                                   

                                  If am running the script again. already 'New Indesign.indd' file in that particular folder, how can we give the alert to message 'Already New Indesign.indd is there' and how can we override the file again the same path with 'New Indesign.indd' this name.

                                   

                                  var path = Folder.selectDialog ("Select folder");

                                  var files = path.getFiles(/\.(indd?|indt?)$/i );

                                       myDocument = app.open(new File(files));

                                  //~     app.activeDocument.save(path.fsName + "\\" + "NewIndesign"+".indd");

                                  myDocument.save(new File(path + "/" + "New Indesign.indd"));

                                  by

                                  hasvi

                                  • 14. Re: How to define log report path
                                    hasvi Level 1

                                    Hi chinna,

                                    here,

                                        try 

                                         myDocument.save(new File(path + "/" + "New Indesign.indd")); 

                                    catch(e) 

                                         alert("A document already exists with the given name! Now its going to override"); 

                                    }

                                    alert("A document already exists with the given name! Now its going to override");

                                     

                                    What is the process for do override the file with same name?

                                     

                                    by

                                    hasvi

                                    • 15. Re: How to define log report path
                                      hasvi Level 1

                                      Hi chinna,

                                       

                                      I write code for override as like below, but its not working. pls help:

                                      var path = Folder.selectDialog ("Select folder");

                                      //~ var files = path.getFiles("*.indd" && "*.indt"),

                                      var files = path.getFiles(/\.(indd?|indt?)$/i );

                                      //~     app.activeDocument.save(path.fsName + "\\" + "NewIndesign"+".indd");

                                      try

                                      {

                                      myDocument.save(new File(path + "/" + "New Indesign.indd"));

                                      }

                                      catch(e)

                                      {

                                      alert ("Already");

                                      myDocument.override(new File(path + "/" + "New Indesign.indd"));

                                       

                                       

                                      }

                                       

                                       

                                      myDocument = app.open(new File(files));

                                       

                                      by

                                      hasvi