-1

I need an InDesign script that does the following:

  • Searching for a specific word in a specific paragraph style throughout the document
  • Printing the page number(s) to the console or as a .txt (I mean not the amount of pages, but the page number(s), i.e. p6, p11, p48 etc)

I am using CS6 and JS.

VHS
  • 71
  • 3
  • 13

1 Answers1

0

This should get you started:

app.findGrepPreferences=NothingEnum.NOTHING; //to reset the Grep search
app.findGrepPreferences.findWhat = 'Your text will be here'; //the word(s) you are searching
app.findGrepPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.itemByName ("The name of your paragraph Style") //make sure it is spelled exactly as it is in the paragraph styles panel, including case
var fnd = app.activeDocument.findGrep (); //execute search
for (var i = 0; i < fnd.length; i++) { //loop through results and store the results
    $.write (fnd [i].parentTextFrames[0].parentPage.name + '\n'); //output to console in Extendscript
}

One thing to know is that text frames outside the pages (on pasteboard) will cause this script to error so you need to try/catch it. But this is the general idea. Also this works in CC but in CS there was no 'parentPage' so this might need to be worked around.

Michael
  • 75
  • 9