Skip to main content
Inspiring
April 29, 2014
Question

Output function (results to a file) in Extendscript

  • April 29, 2014
  • 1 reply
  • 1221 views

When I check a script I use the alert to see if the code is working, such as "Current tag is body".

Is there a function that outputs alert results to a file? For example, a way to send to a file all

of the paragraph tags that are used in a document. (The actual code could be a loop). I could

use this as a start to produce what I really want, an array of all the valid tags, and then print to a file

a list of all the "rogue" tags that are not in the valid list

This topic has been closed for replies.

1 reply

4everJang
Legend
April 29, 2014

Check the JavaScript Tools Guide for details about the File object. Basically, it works more or less like this:

var oFile = new File ( /* full path name as text string */ );

oFile.open( "w" );     /* use "a" to append, "w" to remove existing text.

oFile.writeln ( "Whatever you want to write in there" );

oFile.close (  );

Ciao

Jang

klk_ncAuthor
Inspiring
April 30, 2014

Here's the code I have, but the Extendscript debugger says oFile.open is not a function, is this only for javascript?

Thanks,

Keith

function processDoc (doc) {

        //Process the paragraphs and tables in the main document flow

 

        var textList, count = 0, i = 0, tbl = 0, pgf = 0;

        var oFile = "c:\myname\tags-list.txt";

        // Turn off the document display to speed the script and

        // prevent screen flicker.

        if (app.Displaying == 1) {

        app.Displaying = 0;

        }

       

        //Process each top-level paragraph in document

       

        oFile.open("a");

        pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

        while (pgf.ObjectValid()) {

       

    //!!    applyNewPgfFmt(pgf,doc);

   

    oFile.Writeln(pgf.Name);

           

            pgf = pgf.NextPgfInFlow;

        }

       

    oFile.close();

klk_ncAuthor
Inspiring
April 30, 2014

OK, was in a hurry, see that the new is a resreved word, this should be closer, there are no errors but no text output, I'll keep trying...

//Process the paragraphs and tables in the main document flow

 

        var textList, count = 0, i = 0, tbl = 0, pgf = 0;

        var tagsFile = new File ("C:\extend\tag_list.txt")

        // Turn off the document display to speed the script and

        // prevent screen flicker.

        if (app.Displaying == 1) {

        app.Displaying = 0;

        }

       

        //Process each top-level paragraph in document

       

        tagsFile.open("a");

        pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

        while (pgf.ObjectValid()) {

       

    //!!    applyNewPgfFmt(pgf,doc);

   

            tagsFile.writeln (pgf.NextPgfInFlow);

           

            // pgf = pgf.NextPgfInFlow;

        }

       

    tagsFile.close();