I am using a script to copy sequential lines from an input text file into an InDesign document. I have used the script a number of times with no problems.

var fi = new File("C:/Documents/input.txt")     //Change to the path of your input file  
     alert("Input file does not exist")  
var data = fi.read() .split('\n')  
app.findGrepPreferences.findWhat = "†"
var res = app.selection[0].parentStory.findGrep(true)  //when set to 'false', replace starts from end of input file
data = data.slice(0, res.length)  
while(a = res.shift())  
     a.contents = data.pop()
app.findGrepPreferences = NothingEnum.nothing;  

I am currently working on a file with thousands of footnotes each with the dummy text "†" in the note. I would like to sequentially replace each dummy placeholder with a line from an input file.

The problem is, no matter what I do, the script starts at footnote 18. So, input-line-1 maps to footnote 18, not footnote 1 and so the whole copy and paste is out of sequence.

How can this behaviour be fixed?

I have tried the following:

  1. delete first frame of story, create new text frame, then re-thread (has the effect of assigning new ID to text frame)
  2. delete first footnote, then replace again (which did have the effect of searches within InDesign starting from the first footnote, but not so when using the script)
  3. saving a copy of the document and then trying again with the copied document.
  4. I have tried a version of the script which uses "var res = app.selection[0].parentStory.findGrep(true)" in line 11 and one that uses "var res = app.documents[0].findGrep(true)"
  5. I have tried starting the script with my cursor in different positions: in the story, in the footnote, nothing selected

So, how can I get a search in InDesign to begin at the beginning (i.e. from footnote 1, not footnote 18?)

The script uses a GREP search. Would a plain text search work better?

Thank you!

  • I also tried a plain text search rather than GREP, using "app.findTextPreferences" in line 10. The script starts pasting at footnote 1 (as desired) but then restarts at footnote 18 (not desired!). The pasting is then all out of sequence with the gap eventually narrowing and then everything is in sequence from not 2,914 until the end (strange!)
    – Ad Astm
    Nov 6, 2019 at 11:52
  • I wonder if footnote 18 is actually the one that was created first and if that's then then reason that the GREP search starts at this footnote. Could you check the footnotes ID? If that were the case then you could sort all search results by their footnote ID or something like that.
    – mdomino
    Nov 6, 2019 at 14:54
  • Also, in the GREP search, does the script eventually replace footnote 1 at some point or does it leave it as is?
    – mdomino
    Nov 6, 2019 at 14:55

1 Answer 1


Thank you for the helpful suggestions. There are only 4 master pages and no footnotes in there (I also checked hidden layers etc.)

The script seems fine and the input file seems fine so I began focussing on the document.

I found some footnotes in tables that were hidden as invisible formatting. The footnote markers were displaying as "". These markers show as dynamic footnotes in story editor and I can right click them and choose "Go to Footnote Text" in the contextual menu.

Notes cannot be inserted in a table. The relevant menu option is disabled. These phantom notes came into being through a find and replace, where the found item was replaced with the clipboard contents (which happened to be a footnote)

These phantom notes are not included in the footnote marker sequence so I get a sequence of markers as follows:

...2908, 2909, , , , 2910, 2911...

However, the corresponding footnote text sequence does not jump so I get:

...2908, 2909, 2910, 2911, 2912, 2913, 2914...

Hence, there is a mismatch.

I got rid of the mismatch and finished what I needed to do. Thanks again for your support.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.