12 Replies Latest reply on Mar 25, 2010 11:31 PM by Harbs.

    Issues with export/save text file from Indesign

    Thomas B. Nielsen Level 3

      Hi scripters,

       

      I have a problem that i do not know how to solve.

      Indesign CS3, Mac and PC - only seen the problem on some macs, not all, but some always have/get this error.

       

      I made a script that collects text from selected textframes:

       

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

      var curTF = myMainList[i];

      while (curTF != null) {

      myExportString += curTF.contents;

      curTF = curTF.nextTextFrame;

      }

      myExportString += "\n\n###############################\n\n";

      }

      alert(myExportString);

       

       

      This collects the text and also it will display ok in the dialog.

       

      However on some computers (macs) the following will only produce a zero byte file (when there is more than one textframe in the loop above, a zero byte file is always produced - but again it's only on some macs) If a single textFrame with only a small amount of text is saved/exported it works:

       

      var myFolder = Folder.myDocuments.path + "/Desktop/Export";

      //alert("Myfolder: " + myFolder);

       

      if(!myFolder.exists) {

      Folder(myFolder).create();

      }

       

      var myFileName = myFolder + "/" +win.FilePnl.FileGrp.FileName.text + ".txt";

      var myFile = new File (myFileName);

      myFile.encoding = 'text';

      myFile.open ("w");

      myFile.write (myExportText.replace("/\u2011/g",'-'));//replace(/[^a-zA-Z 0-9]+/g,''));

      myFile.close();

       

      Has this got to do with using .contents?

      I hope someone can help me with this, been working on this problem for way to long now.

       

      Thomas