Javascript InDesign脚本搜索单词并打印页码

Javascript InDesign脚本搜索单词并打印页码,javascript,adobe-indesign,Javascript,Adobe Indesign,我需要执行以下操作的InDesign脚本: 在整个文档中以特定段落样式搜索特定单词 将页码打印到控制台或以.txt格式打印(我指的不是页数,而是页码,即p6、p11、p48等) 我正在使用CS6和JS。这应该让您开始: app.findGrepPreferences=NothingEnum.NOTHING; //to reset the Grep search app.findGrepPreferences.findWhat = 'Your text will be here'; //the

我需要执行以下操作的InDesign脚本:

  • 在整个文档中以特定段落样式搜索特定单词
  • 将页码打印到控制台或以.txt格式打印(我指的不是页数,而是页码,即p6、p11、p48等)

我正在使用CS6和JS。

这应该让您开始:

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
}
app.findgrepreferences=nothingeum.NOTHING//重置Grep搜索
app.findgrepreferences.findWhat='您的文本将在此处'//您正在搜索的单词
app.findgrepreferences.appliedParagraphStyle=app.activeDocument.paragraphStyles.itemByName(“段落样式的名称”)//确保其拼写与“段落样式”面板中的拼写完全一致,包括大小写
var fnd=app.activeDocument.findGrep()//执行搜索
对于(var i=0;i

需要知道的一件事是,页面外的文本框(在粘贴板上)将导致此脚本出错,因此您需要尝试/捕获它。但这是总的想法。这也适用于CC,但在CS中没有“父页面”,因此可能需要解决这一问题。

您需要展示您迄今为止所做的工作。