29 Replies Latest reply on Nov 20, 2008 7:47 PM by (3poulakia)

    looking for a script to import/export all footnotes on a MAC/CS3

      To all you amazing scripting gurus,

      CS3 on a MAC. I am faced with an awkward situation. I am given a 300+ scientific document with 400+ footnotes that they keep on changing ALL THE TIME.

      i Is there a script that would import into inDesign the footnotes from another doc/txt/csv file and replace the ones to their already existing reference avoiding overflows and at the same time applying a defined paragraph style? As an extra bonus it would be even greater if one could have an option do the reverse. That is to select all the existing footnotes in an indesign document and export them to a doc/txt/csv file. This way editors can play to their heart's desire and it would be a real treat for designers.

      I know it is quite a challenge since inDesign does not even have an option to select all footnotes. But I've seen what you experts can do with scripts.

      Keeping my hopes high, thank you all in advance
      Michael
        • 1. Re: looking for a script to import/export all footnotes on a MAC/CS3
          Kasyan Servetsky Level 5
          Hi Michael,

          You don’t need a script for this, as InDesign combined with InCopy (http://www.adobe.com/products/incopy/ ) already has this functionality.
          Briefly, InCopy is a text editor made to work together with InDesign and having the same functionality for working with text as InDesign has. It will enable you and your editors to work on the same InDesign document simultaneously. You just have to decide which stories you want the editors to edit — all stories in the document / on the active layer / selection — and choose Edit > InCopy > Export. After that these stories become available to editors for editing in InCopy. You can edit the text in InDesign as well, but two people can’t edit the same text at the same time of course — if somebody has already opened a text, it becomes locked for others. You can even work with your editors remotely: via e-mail.
          InDesign and InCopy are totally cross platform, so if you work on Mac and the editors on PC, no problems will occur as far as you use the same set of fonts.
          We’ve been using this workflow for a few years and now can’t even imagine our life without InCopy.

          Kasyan
          • 2. Re: looking for a script to import/export all footnotes on a MAC/CS3
            Level 1
            Hi Kasyan and thanx for the quick reply,

            Still, I think you are talking about a completely different ball game.
            You see I know that for the time being this would be both a money issue (since neither myself -I only have Bridge/Photoshop/InDesign CS3- or the editor who happens to be the college secretary, have InCopy) as well as a time issue (since, as I saw at the Adobe site, it would take quite some training hours for the two of us in order to have decent results). Quite unfortunate but true.
            Still your answer is highly appreciated.

            So the question still remains for you or anyone else that could probably provide any kind of help.
            b Is there a script that could do the above?

            Thank you in advance
            Michael
            • 3. Re: looking for a script to import/export all footnotes on a MAC/CS3
              Kasyan Servetsky Level 5
              >Is there a script that could do the above?

              In all likelihood there is no such a script. I’ve been monitoring this forum for a few years and keep an eye on different sites but never came across it.

              But here is what I knocked up: 2 scripts – one of them exports contents of footnotes into separate text files into a “Footnotes” folder on the desktop.
              The names of files are as made like so:
              First three words_ StoryId_ FootnoteId.txt
              Where – “First three words” is for humans, and “StoryId_ FootnoteId” for the script — to differentiate footnotes.
              It’s a very raw, preliminary and totally not tested version – just to give you idea how this can be done. The final version depends of your workflow.
              You can download them from here: http://www.kasyan.ho.com.ua/footnotes.html

              Kasyan



              // footnotes2text script for InDesign CS3
              footnotes2text();

              function footnotes2text(){
                 var myFolder = new Folder ("~/Desktop/Footnotes");
                 if (!myFolder.exists) {
                    myConfirm = confirm("Folder \"Footnotes\" does not exist. Do you want to create it?");
                    if (myConfirm){
                       myFolder.create();
                    }
                    else{
                       exit();
                    }
                 }
                 var myDoc = app.activeDocument;
                 for( var i = 0; i < myDoc.stories.length; i++ ) {
                    var myStory = myDoc.stories[i];
                    var myFnotes = myStory.footnotes;
                    for( var j = 0; j < myFnotes.length; j++ ) {
                       var my1st3words = myFnotes[j].words.itemByRange(0, 2).contents;
                       var myFilePath = myFolder + "/" + my1st3words + "_" + myStory.id + "_" + myFnotes[j].id + ".txt";
                       var myFile = new File(myFilePath);
                       myFile.open("w");
                       myFile.write(myFnotes[j].contents);
                       myFile.close();
                    }
                 }
              }



              // text2footnotes script for InDesign CS3
              text2footnotes();

              function text2footnotes() {
                 var myFolder = new Folder ("~/Desktop/Footnotes");
                 if (!myFolder.exists) {
                    myConfirm = confirm("Folder \"Footnotes\" does not exist. Do you want to create it?");
                    if (myConfirm){
                       myFolder.create();
                    }
                    else{
                       exit();
                    }
                 }
                 var myDoc = app.activeDocument;
                 for( var i = 0; i < myDoc.stories.length; i++ ) {
                    var myStory = myDoc.stories[i];
                    var myFnotes = myStory.footnotes;
                    for( var j = 0; j < myFnotes.length; j++ ) {
                       var my1st3words = myFnotes[j].words.itemByRange(0, 2).contents;
                       var myFilePath = myFolder + "/" + my1st3words + "_" + myStory.id + "_" + myFnotes[j].id + ".txt";
                       var myFile = new File(myFilePath);
                       if (myFile.exists) {
                          myFile.open("r");
                          myFnotes[j].contents = myFile.read();
                          myFile.close();
                       }
                    }
                 }
              }
              • 4. Re: looking for a script to import/export all footnotes on a MAC/CS3
                Level 1
                Hi Kasyan,

                I tried the scripts but they both seem to get stuck giving an error at:

                Error Number: 45
                Error String: Object is invalid
                Line: 20
                Source: var my1st3words = myFnotes[j].words.itemByRange(0, 2).contents;

                Any suggestions?

                Thank you
                Michael

                By the way. I work on another script script and managed to import a jpg's filename into the images caption. But it imports the extension as well. How can I get rid of that?

                var md = sels[i].synchronousMetadata;
                md.namespace = "http://ns.adobe.com/photoshop/1.0/";
                md.Caption = sels[i].name;
                • 5. Re: looking for a script to import/export all footnotes on a MAC/CS3
                  Level 1
                  I solved the mystery of the jpg's filename into the images caption. I replaced the above code with this one.

                  var md = sels[i].synchronousMetadata;
                  md.namespace = "http://ns.adobe.com/photoshop/1.0/";
                  md.Caption = sels[i].name.replace (/\.[^.]+$/, "");
                  • 6. Re: looking for a script to import/export all footnotes on a MAC/CS3
                    Kasyan Servetsky Level 5
                    I tested it on a very simple document: one page and 3 footnotes. Its hard for me to foresee what is going on with the document that you are working on.
                    Lets make a step backward and remove the problem line to make things simpler:

                    // footnotes2text script for InDesign CS3
                    
                    footnotes2text();

                    function footnotes2text(){
                       var myFolder = new Folder ("~/Desktop/Footnotes");
                       if (!myFolder.exists) {
                          myConfirm = confirm("Folder \"Footnotes\" does not exist. Do you want to create it?");
                          if (myConfirm){
                             myFolder.create();
                          }
                          else{
                             exit();
                          }
                       }
                       var myDoc = app.activeDocument;
                       for( var i = 0; i < myDoc.stories.length; i++ ) {
                          var myStory = myDoc.stories[i];
                          var myFnotes = myStory.footnotes;
                          for( var j = 0; j < myFnotes.length; j++ ) {
                             var myFilePath = myFolder + "/" + myStory.id + "_" + myFnotes[j].id + ".txt";
                             var myFile = new File(myFilePath);
                             myFile.open("w");
                             myFile.write(myFnotes[j].contents);
                             myFile.close();
                          }
                       }
                    }

                    // text2footnotes script for InDesign CS3
                    
                    text2footnotes();

                    function text2footnotes() {
                       var myFolder = new Folder ("~/Desktop/Footnotes");
                       if (!myFolder.exists) {
                          myConfirm = confirm("Folder \"Footnotes\" does not exist. Do you want to create it?");
                          if (myConfirm){
                             myFolder.create();
                          }
                          else{
                             exit();
                          }
                       }
                       var myDoc = app.activeDocument;
                       for( var i = 0; i < myDoc.stories.length; i++ ) {
                          var myStory = myDoc.stories[i];
                          var myFnotes = myStory.footnotes;
                          for( var j = 0; j < myFnotes.length; j++ ) {
                             var myFilePath = myFolder + "/" + myStory.id + "_" + myFnotes[j].id + ".txt";
                             var myFile = new File(myFilePath);
                             if (myFile.exists) {
                                myFile.open("r");
                                myFnotes[j].contents = myFile.read();
                                myFile.close();
                             }
                          }
                       }
                    }
                    • 7. Re: looking for a script to import/export all footnotes on a MAC/CS3
                      Kasyan Servetsky Level 5
                      >But it imports the extension as well. How can I get rid of that?

                      I know a few more ways:

                      //creates an array from a string
                      //returns the first item in the array
                      myLink.name.split(".")[0];

                      var basename = docName.match(/(.*)\.[^\.]+$/)[1];

                      //Strip off the file type extension (dot and 3 characters)
                      myFileName.slice(0,-4);

                      function getFileNameOnly (myFileName) {
                      var myString = "";
                      var myResult = myFileName.lastIndexOf(".");
                      if (myResult == -1) {
                      myString = myFileName;
                      }
                      else {
                      myString = myFileName.substr(0, myResult);
                      }
                      return myString;
                      }
                      • 8. Re: looking for a script to import/export all footnotes on a MAC/CS3
                        Level 1
                        Kasyan,

                        I still get the same error. Could it be due to my file itself? If it is any help, you can find the file here.
                        http://www.aenaon.info/toget/footnotesTEST.indd.zip

                        Also thank you for the tips on removing the file extensions. They come really handy.

                        Michael
                        • 9. Re: looking for a script to import/export all footnotes on a MAC/CS3
                          (Simon_Paterson) Level 1
                          I feel for you and your problem... I see typesetters all over the planet reaching out to choke the editors on your project. Good on you, Kasyan, for helping as you are.
                          • 10. Re: looking for a script to import/export all footnotes on a MAC/CS3
                            Kasyan Servetsky Level 5
                            Hi Michael,

                            Now I see that your text is in Greek (or at least I think its in Greek, may be its some other language), so we have to change encoding to Unicode:
                            myFile.encoding = "UTF8";
                            

                            I tried to edit text on Mac in TextEdit and on PC in Notepad, and it works for me.
                            But a new problem appeared: when I import footnotes back into ID document Im loosing footnote numbering.
                            Try these scripts and let me know if it works for you.

                            Kasyan



                            // footnotes2text script for InDesign CS3
                            footnotes2text();

                            function footnotes2text(){
                               if(app.documents.length == 0){
                                  alert("Please open a document and try again.");
                                  exit();
                               }
                               var myFolder = new Folder ("~/Desktop/Footnotes");
                               if (!myFolder.exists) {
                                  myConfirm = confirm("Folder \"Footnotes\" does not exist. Do you want to create it?");
                                  if (myConfirm){
                                     myFolder.create();
                                  }
                                  else{
                                     exit();
                                  }
                               }
                               var myDoc = app.activeDocument;
                               for( var i = 0; i < myDoc.stories.length; i++ ) {
                                  var myStory = myDoc.stories[i];
                                  var myFnotes = myStory.footnotes;
                                  for( var j = 0; j < myFnotes.length; j++ ) {
                                     var myLetters = myFnotes[j].characters.itemByRange(3, 23).contents;
                                     var myFilePath = myFolder + "/" + myLetters + "_" + myStory.id + "_" + myFnotes[j].id + ".txt";
                                     var myFile = new File(myFilePath);
                                     myFile.open("w");
                                     myFile.encoding = "UTF8";
                                     myFile.write(myFnotes[j].contents);
                                     myFile.close();
                                  }
                               }
                            }



                            // text2footnotes script for InDesign CS3
                            text2footnotes();

                            function text2footnotes() {
                               if(app.documents.length == 0){
                                  alert("Please open a document, select an object, and try again.");
                                  exit();
                               }
                               var myFolder = new Folder ("~/Desktop/Footnotes");
                               if (!myFolder.exists) {
                                  myConfirm = confirm("Folder \"Footnotes\" does not exist. Do you want to create it?");
                                  if (myConfirm){
                                     myFolder.create();
                                  }
                                  else{
                                     exit();
                                  }
                               }
                               var myDoc = app.activeDocument;
                               for( var i = 0; i < myDoc.stories.length; i++ ) {
                                  var myStory = myDoc.stories[i];
                                  var myFnotes = myStory.footnotes;
                                  for( var j = 0; j < myFnotes.length; j++ ) {
                                     var myLetters = myFnotes[j].characters.itemByRange(3, 23).contents;
                                     var myFilePath = myFolder + "/" + myLetters + "_" + myStory.id + "_" + myFnotes[j].id + ".txt";
                                     var myFile = new File(myFilePath);
                                     if (myFile.exists) {
                                        myFile.open("r");
                                        myFnotes[j].contents = myFile.read();
                                        myFile.close();
                                     }
                                  }
                               }
                            }
                            • 11. Re: looking for a script to import/export all footnotes on a MAC/CS3
                              Level 1
                              Kasyan,

                              It looks Greek, it feels Greek, it is Greek.

                              Still... You are getting there. It DID export 6 out of the 7 footnotes (unfortunately). For some reason it ignores the one of the footnote. Furthermore it was all gibberish. So I changed the "Plain Text Encoding" on my TextEdit app by adding UTF-8 and the Greek ISO 8859-7 and all went almost well. The problem was that I still got ONLY 6 out of the 7 footnotes.
                              Could this be the reason that the numbering gets messed up when trying to import them back? It happened to me too.

                              So I put the footnotes2txt script to a real test. I ran it on a 140 pages/370 footnotes document. Many times. Again it would stop on specific points in the text. By deleting, altering or changing both the text or its formatting of the footnotes text or what precedes or follows the footnote number, I got different results but I can not figure out a pattern. And scripting IS all Greek to me. :-( Could this have to do with the formatting? Or ....

                              Anyway, thinking as well of points of ergonomically improving it, I wonder if you could:
                              1. give a prefix to the files like 001_ , 002_ , 003_ , etc as well (deriving from the footnote's number). This way one could seek through a numbering and not alphabetical order (which is a bit confusing when dealing with 300+ files). It could probably help the script itself.
                              2. use an xls file (it reads utf-8 correctly; doesn't it?) instead of txt. So one does not have to open/edit/save 370 different files. You also get a free bonus numbered list field right in the beginning. Still when copied back it should not carry any formating.
                              3. have it display an "ALL DONE" message in the end, so one knows it's finished.
                              4. make sure it does not produse any overflows after importing.
                              5. give it a thought on how it would behave in a book situation (many) indd packaged together. After all this is how long documents are usually handled.

                              If you can pull this together it would be quite an achievement. Keeping my fingers crossed.
                              Michael
                              • 12. Re: looking for a script to import/export all footnotes on a MAC/CS3
                                Kasyan Servetsky Level 5
                                1.Done
                                2.Describe me step by step how to do it manually.
                                3.Done
                                4.I think its impossible to do via scripting, even if I try to do it e.g. fit frame to content or by changing height or width of the frame, the frame can go outside the page. By the way, InCopy controls copy fitting shows how many lines, words, characters are under/overflown.
                                5.Send me a sample book ID with files.



                                // footnotes2text script for InDesign CS3
                                footnotes2text();

                                function footnotes2text(){
                                   if(app.documents.length == 0){
                                      alert("Please open a document and try again.");
                                      exit();
                                   }
                                   var myFolder = new Folder ("~/Desktop/Footnotes");
                                   if (!myFolder.exists) {
                                      myConfirm = confirm("Folder \"Footnotes\" does not exist. Do you want to create it?");
                                      if (myConfirm){
                                         myFolder.create();
                                      }
                                      else{
                                         exit();
                                      }
                                   }
                                   var myDoc = app.activeDocument;
                                   for( var i = 0; i < myDoc.stories.length; i++ ) {
                                      var myStory = myDoc.stories[i];
                                      var myFnotes = myStory.footnotes;
                                      for( var j = 0; j < myFnotes.length; j++ ) {
                                         var myFilePath = myFolder + "/" + getNumber(myFnotes[j].index + 1) + "_" + myStory.id + ".txt";
                                         var myFile = new File(myFilePath);
                                         myFile.open("w");
                                         myFile.encoding = "UTF8";
                                         myFile.write(myFnotes[j].contents);
                                         myFile.close();
                                      }
                                   }
                                   alert("All done");
                                }

                                function getNumber(myNumber) {
                                   return ('000'+myNumber).match (/...$/)[0];
                                }



                                // text2footnotes script for InDesign CS3
                                text2footnotes();

                                function text2footnotes() {
                                   if(app.documents.length == 0){
                                      alert("Please open a document, select an object, and try again.");
                                      exit();
                                   }
                                   var myFolder = new Folder ("~/Desktop/Footnotes");
                                   if (!myFolder.exists) {
                                      myConfirm = confirm("Folder \"Footnotes\" does not exist. Do you want to create it?");
                                      if (myConfirm){
                                         myFolder.create();
                                      }
                                      else{
                                         exit();
                                      }
                                   }
                                   var myDoc = app.activeDocument;
                                   for( var i = 0; i < myDoc.stories.length; i++ ) {
                                      var myStory = myDoc.stories[i];
                                      var myFnotes = myStory.footnotes;
                                      for( var j = 0; j < myFnotes.length; j++ ) {
                                         var myFilePath = myFolder + "/" + getNumber(myFnotes[j].index + 1) + "_" + myStory.id + ".txt";
                                         var myFile = new File(myFilePath);
                                         if (myFile.exists) {
                                            myFile.open("r");
                                            myFnotes[j].contents = myFile.read();
                                            myFile.close();
                                         }
                                      }
                                   }
                                   alert("All done");
                                }

                                function getNumber(myNumber) {
                                   return ('000'+myNumber).match (/...$/)[0];
                                }
                                • 13. Re: looking for a script to import/export all footnotes on a MAC/CS3
                                  Level 1
                                  Kasyan,

                                  1. Done. It's magic.... :-)
                                  2. About the excell. I thought that: It supports utf-8 encoding. It has fields with unique numbering values. Each value (row) has many columns. Only the fields on the first column (column A) are going to be used (this is where) the footnote's text is placed. So the footnotes2text script instead of creating (for 434 footnotes) 434 txt files ranging from 001_572 to 434_572 and placing the corresponding text into them, it creates just ONE file (I don't know if the text has to stripped from any formatting). File 572_something (could be the creation date or....). It then fills the cells 1,A to 434,A with the footnotes' corresponding text. So all one has to do is open ONE tidy file, with ALL the footnotes. After editing the cells with new text, when the text2footnotes script runs, it picks up the content (text) of the corresponding cell of just the FIRST column (you can keep notes on the other ones) and places it in the corresponding footnote replacing the existing text.
                                  3. Beautiful 'ALL DONE' after exporting. Sad 'ALL DONE' after importing. You see it is still unable to produce the numbers on the footnotes. Very sad because it makes both scripts unusable. Maybe by using the excell the script could pick up the row's number and place it to what it is now missing. Because the field value in the indd is there. If you click on the footnote it takes you back to the story.
                                  4. This could probably be handled by a different script alltogether or by InDesign itself.
                                  5. I have to be out away from the screen for a few hours. But I will get something ready within the next 24 hours.

                                  You have been great
                                  Michael
                                  • 14. Re: looking for a script to import/export all footnotes on a MAC/CS3
                                    Kasyan Servetsky Level 5
                                    >About the excell...

                                    In JS we are unable to make InDesign to interact with Excel.

                                    So we have two goals by now:
                                    1. solve the disappearing footnote numbers problem
                                    2. make the script to write all footnotes into a single file
                                    • 15. Re: looking for a script to import/export all footnotes on a MAC/CS3
                                      Level 1
                                      i make the script to write all footnotes into a single file

                                      Please do not try csv. I have difficulties with saving the correct encoding. Maybe an rtf or doc file (although I don;t see it. But it is all Greek to me anyway. You know best.

                                      Good luck, if I may say so.
                                      I'm off,
                                      Michael
                                      • 16. Re: looking for a script to import/export all footnotes on a MAC/CS3
                                        Level 1
                                        Kasyan,

                                        Sorry for the delay. I have finaly uploaded a book package here.
                                        http://aenaon.info/toget/footnotes_Book_01_Folder.zip
                                        Did you find anything for the "missing numbers"? As mentioned before the created file (cause there is Greek involved) can be any of xls, xml, utf-16 txt files.

                                        Please let me know what is happening.
                                        Michael
                                        • 17. Re: looking for a script to import/export all footnotes on a MAC/CS3
                                          Level 1
                                          Kasyan,

                                          Snooping around the forum I also found this approach. Could this help you any?

                                          i Pascal Dobbelaere, "Automatic converting footnotes" #, 4 Jun 2008 4:35 am

                                          Michael
                                          • 18. Re: looking for a script to import/export all footnotes on a MAC/CS3
                                            Kasyan Servetsky Level 5
                                            Hi Michael,

                                            Here is a new version of the script. Select a frame in the main story and run footnotes2text script, a text file with the same name as your InDesign document will be created on the desktop. All the footnotes will be saved in this file, separated with # sign (I suppose you don’t use it in the text). Then after the editor edits the text you import the file back.
                                            I tested the scripts on PC, they seem to work – footnotes are preserved. But I found a problem: if a footnote has formatting, e.g. a word in bold, then this formatting is shifted by the amount of characters added or removed. And there is nothing I can do about it by script.

                                            Kasyan



                                            // footnotes2text script for InDesign CS3
                                            footnotes2text();

                                            function footnotes2text(){
                                               if(app.documents.length == 0){
                                                  alert("Please open a document and try again.");
                                                  exit();
                                               }
                                               var myDoc = app.activeDocument;
                                               var myFile = new File("~/Desktop/" + myDoc.name.match(/(.*)\.[^\.]+$/)[1] + ".txt");
                                               var myArray = new Array();
                                               var mySel = myDoc.selection[0];
                                               if (myDoc.selection.length == 1 && mySel.constructor.name == "TextFrame") {
                                                  var myStory = mySel.parentStory;
                                               }
                                               else {
                                                  alert("Select a single text frame and try again.");
                                                  exit();
                                               }
                                               var myFnotes = myStory.footnotes;
                                               for( var j = 0; j < myFnotes.length; j++ ) {
                                                  var myFnoteText = (j+1) + "\t" + myFnotes[j].contents.substring(2);
                                                  myArray.push(myFnoteText);
                                               }
                                               myFile.open("w");
                                               myFile.encoding = "UTF8";
                                               myFile.write(myArray.join("#"));
                                               myFile.close();
                                               alert("All done");
                                            }



                                            // text2footnotes script for InDesign CS3
                                            footnotes2text();

                                            function footnotes2text(){
                                               if(app.documents.length == 0){
                                                  alert("Please open a document and try again.");
                                                  exit();
                                               }
                                               var myDoc = app.activeDocument;
                                               var mySel = myDoc.selection[0];
                                               if (myDoc.selection.length == 1 && mySel.constructor.name == "TextFrame") {
                                                  var myStory = mySel.parentStory;
                                               }
                                               else {
                                                  alert("Select a single text frame and try again.");
                                                  exit();
                                               }
                                               var myFile = new File("~/Desktop/" + myDoc.name.match(/(.*)\.[^\.]+$/)[1] + ".txt");
                                               if (myFile.exists) {
                                                        myFile.open("r");
                                                        var myArray = myFile.read().split("#");
                                                        if (myArray.length == 0) {
                                                           alert("Sourse file is empty.");
                                                           exit();
                                                        }
                                                        myFile.close();
                                                     }
                                               else {
                                                  alert("Sourse file does not exist.");
                                                  exit();
                                               }

                                               var myFnotes = myStory.footnotes;
                                               for( var j = 0; j < myFnotes.length; j++ ) {
                                                  myFnotes[j].contents = myArray[j];
                                               }
                                               alert("All done");
                                            }
                                            • 19. Re: looking for a script to import/export all footnotes on a MAC/CS3
                                              Kasyan Servetsky Level 5
                                              Let’s try another approach – export the text in RTF format and then re-import it as a linked file.
                                              1 Create a copy of your document
                                              2 Select all text in the main story.
                                              3 Export it as RTF file.
                                              4 Then go to Preferences > Type > Links and check on ‘Create Links When Placing Text and Spreadsheet Files’.
                                              5 Import the RTF file, now it should be a linked file, you can edit it in Word and then choose update in the links palette.
                                              • 20. Re: looking for a script to import/export all footnotes on a MAC/CS3
                                                Level 1
                                                Kasyan,

                                                I tried the RTF trick but for some reason when reimported it messes up the formatting of most of the text. I think this is a dead end. Could an xml file be an option?
                                                So for the time being I stick with your script hoping that you find a fix for it.

                                                Waiting (if you still have the time) for the "magic" fix.

                                                Michael
                                                • 21. Re: looking for a script to import/export all footnotes on a MAC/CS3
                                                  (Simon_Paterson) Level 1
                                                  I haven't been tuned into the complete conversation and the machinations of Kasyan's script (what a nice person Kasyan is). I'm wondering if the process could be served by converting italics, bold and other formatting to simple text tags before exporting? For example,
                                                  i italic text
                                                  converted to <i>italic text<\i>. There would need to be consideration of the fact there could be superscripts, subscripts and other formatting like underline, but it is a finite list.

                                                  I guess the bigger problem is that people can sometimes complain about working with these codes in the text. Given that money is a constraint as you mentioned earlier---and InCopy is certainly the best way to deal with the issue overall---I think that you could argue they just have to live with it or cough up the money for InCopy.

                                                  The conversion of formatting to codes is relatively simple and has been discussed before (there is even an example in the scripting guides supplied by Adobe). The search would need to be constrained to the paragraph style applied to the footnotes, and this is simple (you do have a paragraph style applied to the footnotes, don't you... of course you do). The rest of Kasyan's script would work well then. Do the conversion before the script start and reverse the conversion at the end and you have your solution, including formatting.

                                                  Like I said, I haven't been fully tuned into this conversation, but Kasyan did a great job helping with this problem that I think it would be shame not to take advantage of this work. With a small amount of extra time and code it could be expanded to work with text formatting, too.
                                                  • 22. Re: looking for a script to import/export all footnotes on a MAC/CS3
                                                    Kasyan Servetsky Level 5
                                                    I’ve already thought about this approach — demonstrated by ExportHTML.jsx example script. I’ll give it a try when time permits and if I attain any success I’ll let you know about it.

                                                    >Could an xml file be an option?

                                                    I’m afraid it would be very hard for the editor to read and edit the text in an XML-editing application.
                                                    • 23. Re: looking for a script to import/export all footnotes on a MAC/CS3
                                                      Kasyan Servetsky Level 5
                                                      Hi all,

                                                      I made another version of the footnote script that doesn’t scramble formatting (at least, I hope that it doesn’t). Here I applied a different approach:
                                                      First select the text frame, you want to export footnotes from, with black arrow.
                                                      Run the footnotes2text script.
                                                      Text of each footnote is moved into a temporary frame created on the pasteboard. Then the text of this frame is exported in RTF format to the desktop. The file has the same name as InDesign document. Open the file in Word and edit.
                                                      Don’t remove tabs at start of the paragraphs.
                                                      Don’t add/remove paragraphs — the number of paragraphs in a footnote before and after editing should be the same.

                                                      When you finished editing, save and close the file.

                                                      In InDesign, select the frame where the footnotes used to be, and run text2footnotes script.

                                                      Run these scripts on a copy of your document or save it before running the scripts, so that you could revert the document to its original state.

                                                      Kasyan


                                                      // footnotes2text script for InDesign CS3
                                                      footnotes2text();

                                                      function footnotes2text() {
                                                         if (app.documents.length == 0) {
                                                            alert("Please open a document and try again.");
                                                            exit();
                                                         }
                                                         var myDoc = app.activeDocument;
                                                         if (myDoc.viewPreferences.horizontalMeasurementUnits != MeasurementUnits.PICAS || myDoc.viewPreferences.verticalMeasurementUnits != MeasurementUnits.PICAS) {
                                                            alert("Measurement units should be set to picas.");
                                                            exit();
                                                         }
                                                         var myFile = new File("~/Desktop/" + myDoc.name.match(/(.*)\.[^\.]+$/)[1] + ".rtf");
                                                         var mySel = myDoc.selection[0];
                                                         if (myDoc.selection.length == 1 && mySel.constructor.name == "TextFrame") {
                                                            var myStory = mySel.parentStory;
                                                         }
                                                         else {
                                                            alert("Select a single text frame and try again.");
                                                            exit();
                                                         }
                                                         var myFnotes = myStory.footnotes;
                                                         var myParNum = new Array(myFnotes.length);
                                                         var myTextFrame = myDoc.textFrames.add({geometricBounds:[1.9, -15.6, 57, -1.2]});
                                                       
                                                         for ( var j = 0; j < myFnotes.length; j++ ) {
                                                            myParNum[j] = myFnotes[j].texts[0].paragraphs.length;
                                                            var myFnText = myFnotes[j].texts[0].paragraphs.everyItem();
                                                            myFnText.move(LocationOptions.AT_END, myTextFrame.texts[0]);
                                                            myTextFrame.insertionPoints[-1]. contents = "\r";
                                                         }
                                                         app.findTextPreferences = NothingEnum.nothing;
                                                         app.changeTextPreferences = NothingEnum.nothing;
                                                         app.findTextPreferences.findWhat = "^F";
                                                         app.changeTextPreferences.changeTo = "";
                                                         myTextFrame.texts[0].changeText();
                                                          myTextFrame.texts[0].exportFile(ExportFormat.RTF, myFile, false);
                                                         myTextFrame.remove();
                                                          myDoc.insertLabel("footnotes", myParNum.join());
                                                         alert("All done");
                                                      }



                                                      // text2footnotes script for InDesign CS3
                                                      text2footnotes();

                                                      function text2footnotes() {
                                                         if (app.documents.length == 0) {
                                                            alert("Please open a document and try again.");
                                                            exit();
                                                         }
                                                         var myDoc = app.activeDocument;
                                                         if (myDoc.viewPreferences.horizontalMeasurementUnits != MeasurementUnits.PICAS || myDoc.viewPreferences.verticalMeasurementUnits != MeasurementUnits.PICAS) {
                                                            alert("Measurement units should be set to picas.");
                                                            exit();
                                                         }
                                                         var mySel = myDoc.selection[0];
                                                         if (myDoc.selection.length == 1 && mySel.constructor.name == "TextFrame") {
                                                            var myStory = mySel.parentStory;
                                                            var myFnotes = myStory.footnotes;
                                                         }
                                                         else {
                                                            alert("Select a single text frame and try again.");
                                                            exit();
                                                         }
                                                         var myFile = new File("~/Desktop/" + myDoc.name.match(/(.*)\.[^\.]+$/)[1] + ".rtf");
                                                         if (myFile.exists) {
                                                            var myTextFrame = myDoc.textFrames.add({geometricBounds:[1.9, -15.6, 57, -1.2]});
                                                            myTextFrame.place(myFile, false);
                                                         var myFnotes = myStory.footnotes;
                                                         var myParNum = myDoc.extractLabel("footnotes").split(",");
                                                         for ( var j = myFnotes.length-1; j >= 0; j-- ) {
                                                               var myText = myTextFrame.texts[0].paragraphs.itemByRange(myTextFrame.texts[0].paragraphs.length-(myParNum[j]), myTextFrame.texts[0].paragraphs.length-1); // [j-1];
                                                                myFnotes[j].texts[0].insertionPoints[0].contents = "" + (j + 1);
                                                               myText.move(LocationOptions.AT_END, myFnotes[j].texts[0]);
                                                               try {
                                                                  if (myFnotes[j].texts[0].paragraphs.length > 1) {
                                                                     myTextFrame.texts[0].paragraphs[-1].characters[-1].remove();
                                                                  }
                                                                  else if (myTextFrame.texts[0].paragraphs[-1].characters[-1].contents == "\r") {
                                                                     myTextFrame.texts[0].paragraphs[-1].characters[-1].remove();
                                                                  }
                                                               }
                                                               catch (e) {}
                                                            }
                                                         }
                                                         else {
                                                            alert("Sourse file does not exist.");
                                                            exit();
                                                         }
                                                         myTextFrame.remove();
                                                         alert("All done");
                                                      }
                                                      • 24. Re: looking for a script to import/export all footnotes on a MAC/CS3
                                                        Level 1
                                                        Hi Kasyan,

                                                        I ran the script but still get errors.

                                                        Running the footnotes2text stops half the way (on different files in different footnotes.)

                                                        Running the text2footnotes produces an error.

                                                        Michael
                                                        • 25. Re: looking for a script to import/export all footnotes on a MAC/CS3
                                                          Kasyan Servetsky Level 5
                                                          Michael,

                                                          Here is new versions of the scripts that I tested,though in a perfunctory manner, with the file you sent me today.

                                                          Kasyan


                                                          // footnotes2text script for InDesign CS3
                                                          footnotes2text();

                                                          function footnotes2text() {
                                                             if (app.documents.length == 0) {
                                                                alert("Please open a document and try again.");
                                                                exit();
                                                             }
                                                             var myDoc = app.activeDocument;
                                                           
                                                             if (myDoc.viewPreferences.horizontalMeasurementUnits != MeasurementUnits.MILLIMETERS || myDoc.viewPreferences.verticalMeasurementUnits != MeasurementUnits.MILLIMETERS) {
                                                                alert("Measurement units should be set to millimiters.");
                                                                exit();
                                                             }

                                                             var myFile = new File("~/Desktop/" + myDoc.name.match(/(.*)\.[^\.]+$/)[1] + ".rtf");
                                                             var mySel = myDoc.selection[0];
                                                             if (myDoc.selection.length == 1 && mySel.constructor.name == "TextFrame") {
                                                                var myStory = mySel.parentStory;
                                                             }
                                                             else {
                                                                alert("Select a single text frame and try again.");
                                                                exit();
                                                             }
                                                             var myFnotes = myStory.footnotes;
                                                             var myTextFrame = myDoc.textFrames.add({geometricBounds:[8, -400, 241, -5]});
                                                           
                                                             for ( var j = 0; j < myFnotes.length; j++ ) {
                                                                var myFnText = myFnotes[j].texts[0];
                                                                myFnText.insertionPoints[0].contents = "<fnote" + myFnotes[j].id + ">";
                                                                myFnText.insertionPoints[-1].contents = "</fnote>\r";
                                                                myFnText.move(LocationOptions.AT_END, myTextFrame.texts[0]);
                                                             }
                                                             myTextFrame.texts[0].exportFile(ExportFormat.RTF, myFile, false);
                                                             myTextFrame.remove();
                                                             alert("All done");
                                                          }



                                                          // text2footnotes script for InDesign CS3
                                                          footnotes2text();

                                                          function footnotes2text() {
                                                             if (app.documents.length == 0) {
                                                                alert("Please open a document and try again.");
                                                                exit();
                                                             }
                                                             var myDoc = app.activeDocument;
                                                           
                                                             if (myDoc.viewPreferences.horizontalMeasurementUnits != MeasurementUnits.MILLIMETERS || myDoc.viewPreferences.verticalMeasurementUnits != MeasurementUnits.MILLIMETERS) {
                                                                alert("Measurement units should be set to millimiters.");
                                                                exit();
                                                             }

                                                             var mySel = myDoc.selection[0];
                                                             if (myDoc.selection.length == 1 && mySel.constructor.name == "TextFrame") {
                                                                var myStory = mySel.parentStory;
                                                                var myFnotes = myStory.footnotes;
                                                             }
                                                             else {
                                                                alert("Select a single text frame and try again.");
                                                                exit();
                                                             }
                                                             var myFile = new File("~/Desktop/" + myDoc.name.match(/(.*)\.[^\.]+$/)[1] + ".rtf");
                                                             if (myFile.exists) {
                                                                var myTextFrame = myDoc.textFrames.add({geometricBounds:[8, -400, 241, -5]});
                                                                myTextFrame.place(myFile, false);
                                                                app.findGrepPreferences = NothingEnum.nothing;
                                                                app.changeGrepPreferences = NothingEnum.nothing;
                                                                app.findGrepPreferences.findWhat = "(<fnote)(\\d+)(>)( *.*w*d*)(</fnote>)";
                                                                app.changeGrepPreferences.changeTo = "$4";

                                                                var myFinds = myTextFrame.findGrep();
                                                                for ( var j = myFinds.length-1; j >= 0; j-- ) {
                                                                   var myFnId = parseInt(myFinds[j].contents.substr(6, 4));
                                                                   var myFootNote = myFnotes.itemByID(myFnId);
                                                                   if (myFootNote != null) {
                                                                      var myText = myFinds[j].changeGrep();
                                                                      myFnotes[j].texts[0].insertionPoints[0].contents = "" + (j + 1);
                                                                      myText[0].move(LocationOptions.AT_END, myFnotes[j].texts[0]);
                                                                   }
                                                                }
                                                             }
                                                             else {
                                                                alert("Sourse file does not exist.");
                                                                exit();
                                                             }
                                                              myTextFrame.remove();
                                                             alert("All done");
                                                          }
                                                          • 26. Re: looking for a script to import/export all footnotes on a MAC/CS3
                                                            Level 1
                                                            Kasyan,

                                                            I tested the scripts and they work. They take everything out and bring everything back in to the right place.

                                                            With one glitch.

                                                            They leave some kind of a residue behind that marks the file permanently.
                                                            I don't know if it happens on "the way out" or "the way in".
                                                            The result is that if and every time you run the script on the same file, the reference number on the footnote is rewritten. So if you run the script twice, the footnote #12 becomes 1212, 4 times, 12121212.
                                                            I think it must be on the way out when you mark the area of the footnote. After the script text2footnotes runs, it should clean the marks left by footnotes2text. Otherwise it works in an additive way. Hence the result.
                                                            So I guess figuring this out would be the last obstacle.

                                                            Could you please give it another try?

                                                            Thanx again
                                                            Michael
                                                            • 27. Re: looking for a script to import/export all footnotes on a MAC/CS3
                                                              Kasyan Servetsky Level 5
                                                              Now I see the problem.
                                                              One more question:
                                                              Do you always separate footnote numbers by N-space?
                                                              • 28. Re: looking for a script to import/export all footnotes on a MAC/CS3
                                                                Kasyan Servetsky Level 5


                                                                // footnotes2text script for InDesign CS3
                                                                footnotes2text();

                                                                function footnotes2text() {
                                                                   if (app.documents.length == 0) {
                                                                      alert("Please open a document and try again.");
                                                                      exit();
                                                                   }
                                                                   var myDoc = app.activeDocument;
                                                                 
                                                                   if (myDoc.viewPreferences.horizontalMeasurementUnits != MeasurementUnits.MILLIMETERS || myDoc.viewPreferences.verticalMeasurementUnits != MeasurementUnits.MILLIMETERS) {
                                                                      alert("Measurement units should be set to millimiters.");
                                                                      exit();
                                                                   }

                                                                   var myFile = new File("~/Desktop/" + myDoc.name.match(/(.*)\.[^\.]+$/)[1] + ".rtf");
                                                                   var mySel = myDoc.selection[0];
                                                                   if (myDoc.selection.length == 1 && mySel.constructor.name == "TextFrame") {
                                                                      var myStory = mySel.parentStory;
                                                                   }
                                                                   else {
                                                                      alert("Select a single text frame and try again.");
                                                                      exit();
                                                                   }
                                                                   var myFnotes = myStory.footnotes;
                                                                   var myTextFrame = myDoc.textFrames.add({geometricBounds:[8, -400, 241, -5]});
                                                                 
                                                                   for ( var j = 0; j < myFnotes.length; j++ ) {
                                                                      var myFnText = myFnotes[j].texts[0];
                                                                      myFnText.insertionPoints[0].contents = "<fnote" + myFnotes[j].id + ">";
                                                                      myFnText.insertionPoints[-1].contents = "</fnote>\r";
                                                                      myFnText.move(LocationOptions.AT_END, myTextFrame.texts[0]);
                                                                   }
                                                                   app.findGrepPreferences = NothingEnum.nothing;
                                                                   app.changeGrepPreferences = NothingEnum.nothing;
                                                                   app.findGrepPreferences.findWhat = "(<fnote)(\\d+)(>)(\\d+)(~>)( *.*w*d*)(</fnote>)";
                                                                   app.changeGrepPreferences.changeTo = "$1$2$3$5$6$7";
                                                                   myTextFrame.texts[0].changeGrep();
                                                                   myTextFrame.texts[0].exportFile(ExportFormat.RTF, myFile, false);
                                                                   myTextFrame.remove();
                                                                   alert("All done");
                                                                }
                                                                • 29. Re: looking for a script to import/export all footnotes on a MAC/CS3
                                                                  Level 1
                                                                  Hi Kasyan,

                                                                  The latest code NO more rewrites the numbers, Excellent work.
                                                                  It does however, still mess up the formatting (italics, bolds, etc) if there is any. I think it moves them according to the number of characters preceding the first formatting.
                                                                  And does not like paragraphs (even if they preexist in the footnote. That is one must have one paragraph footnotes). It also meddles with kern (changes it from optical that I now use to Metrics) and adds ligatures.
                                                                  Nevertheless, it fulfills my immediate needs since all of the footnotes I have are single paragraphs and there is hardly any formatting in them. The ones that have I will handle manually.
                                                                  As for the N-space question. This is what I use 99% of the times (I find the space it gives quite pleasing).

                                                                  I will keep on checking this post in case you want and still feel up to perfecting the script.

                                                                  Thank you so much
                                                                  Michael