Skip navigation
Currently Being Moderated

Save log file on Desktop

Nov 16, 2011 11:08 PM

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


 
Replies
  • aanavaras
    30 posts
    Mar 12, 2010
    Currently Being Moderated
    Nov 16, 2011 11:43 PM   in reply to designmon79

    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

     
    |
    Mark as:
  • aanavaras
    30 posts
    Mar 12, 2010
    Currently Being Moderated
    Nov 17, 2011 1:35 AM   in reply to designmon79

    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....

     
    |
    Mark as:
  • aanavaras
    30 posts
    Mar 12, 2010
    Currently Being Moderated
    Nov 17, 2011 6:10 AM   in reply to designmon79

    Yes Mon.

     

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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points