5 Replies Latest reply on Nov 17, 2011 6:10 AM by aanavaras

    Save log file on Desktop

    designmon79 Level 1

      Hi,

       

      I have created a script (see below) which alert unused character and paragraph style in active document.

      ////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////
      My Script
      ////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////

      myUnusedParagraphStyleName();
      myUnusedCharacterStyleName();


      function myUnusedParagraphStyleName()
      {
      var myDoc = app.activeDocument;
      var myParStyles = myDoc.allParagraphStyles;
      var foundPStyles = [];
      for (i = myParStyles.length-1; i >= 2; i-- ){
      foundPStyles.push(myParStyles.[i].name);
      }
      alert(foundPStyles.join("\r       "));
      }
      function myUnusedCharacterStyleName()

      {
      var myDoc = app.activeDocument;
      var myCharStyles = myDoc.allCharacterStyles;
      var foundCStyles = [];
      for (i = myCharStyles.length-1; i >= 1; i-- ){
      foundCStyles.push(myCharStyles.[i].name);
      }
      alert(foundCStyles.join("\r       "));
      }
      ////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////

       

      But I want to save my alert message as a log file on my Desktop. I have search and found an example (see below) but I couldn't merge this code with my script.

       

      Can anybody please merge this code within my JS. So that my script save a log file in desktop. I really appreciate all your support.

       

      ////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////
      Example taken from Adobe Forum
      ////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////

      var myDoc = app.activeDocument;
      var myDocPath = myDoc.filePath;
      var myDocName = myDoc.name;
      app.findGrepPreferences = app.changeGrepPreferences = null;
      app.findGrepPreferences.findWhat = "\\b(\\w.+\\s000\\s000\\s00)";


      var mySearch = myDoc.findGrep();
      var myFound = new Array()
      for (var j = 0; j < mySearch.length; j++)
      {
      myFound.push (mySearch[j].contents);
      }
      alert(myFound);
      var inc=0;
      var myLogFile = new File(myDocPath.fsName + "/Report_" + myDocName.split(".")[0] +".txt");
      if(myLogFile.open("w", undefined, undefined))
      {
      myLogFile.writeln("Tool name : Report Generator for CS5");
      myLogFile.writeln("************************************");
      if(myFound.length != 0)
      {
              myLogFile.writeln("");
              for (var k = 0; k<myFound.length; k++)
        {
         serialno = k + 1;
         myLogFile.writeln("  "+serialno+".  "+myFound[k]);
               }

      myLogFile.execute();
      }

        else
        {
         myLogFile.writeln("No terms found");
        }
      }
      ////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////

       

       

      Thanks in advance.
      Mon


        • 1. Re: Save log file on Desktop
          aanavaras Level 1

          Here is it.

          var foundPStyles = [];

          var foundCStyles = [];

          var myDoc = app.activeDocument;

          var myDocPath = myDoc.filePath;

          var myDocName = myDoc.name;

           

           

          myUnusedParagraphStyleName();

          myUnusedCharacterStyleName();

          myWrite2Log();

           

           

          function myUnusedParagraphStyleName()

          {

                    var myParStyles = myDoc.allParagraphStyles;

                    for (i = myParStyles.length-1; i >= 2; i-- )

                    {

                              foundPStyles.push(myParStyles[i].name);

                    }

                    // alert(foundPStyles.join("\r       "));

          }

          function myUnusedCharacterStyleName()

          {

                    var myCharStyles = myDoc.allCharacterStyles;

                    for (i = myCharStyles.length-1; i >= 1; i-- ){

                              foundCStyles.push(myCharStyles[i].name);

                    }

                    // alert(foundCStyles.join("\r       "));

          }

          function myWrite2Log()

          {

                    var inc=0;

                    var myLogFile = new File(Folder.desktop+"/Report.txt");

                    if(myLogFile.open("w", undefined, undefined))

                    {

                      myLogFile.writeln("Unused ParaGraph Styles\n=======================\n\r");

                      if(foundPStyles.length != 0)

                      {

                                myLogFile.writeln("");

                                for (var k = 0; k<foundPStyles.length; k++)

                                {

                                          serialno = k + 1;

                                          myLogFile.writeln("\t"+serialno+".\t"+foundPStyles[k]);

                                }

                      }

                      else

                      {

                                myLogFile.writeln("\nNo Unused ParaGraph Styles Found\n\n");

                      }

           

           

                      myLogFile.writeln("\n\nUnused Character Styles\n=======================\n\r");

                      if(foundCStyles.length != 0)

                      {

                                myLogFile.writeln("");

                                for (var k = 0; k<foundCStyles.length; k++)

                                {

                                          serialno = k + 1;

                                          myLogFile.writeln("\t"+serialno+".\t"+foundCStyles[k]);

                                }

                      }

                      else

                      {

                                myLogFile.writeln("\nNo Unused Character Styles Found");

                      }

                    }

               myLogFile.close();

          }

           

           

          Hope this Helps to you

          • 2. Re: Save log file on Desktop
            designmon79 Level 1

            Hi Aanavaras,

             

            Thanks for your support and correct answer.

             

             

            One more questions: It is working well in active document but when I run this on several InDesign file within my Batch Folder my report file saves only 1 Indesign document report.

             

            Is anybody have any idea?

             

            Please help on this.

             

            Thanks,

            Mon

            • 3. Re: Save log file on Desktop
              aanavaras Level 1

              Replace the Line:

              var myLogFile = new File(Folder.desktop+"/Report.txt");

              as

              var myLogFile = new File(Folder.desktop+"/"+myDocName.replace(/\.[^.]+$/,"")+"_Report.txt");

              this will create the Log Report preceding with the Name of the InDesign File....

              • 4. Re: Save log file on Desktop
                designmon79 Level 1

                Thanks for quick reply.

                 

                It saves separate indesign report file on desktop whereas I need to combined all indesign file report in single report text file.

                 

                Is it possible? Please help

                 

                Mon

                • 5. Re: Save log file on Desktop
                  aanavaras Level 1

                  Yes Mon.

                   

                  Create the Log Report before you loop through the InDesign files and Close after the Loop.