首页 > 解决方案 > InDesign 脚本搜索单词并打印页码

问题描述

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

我正在使用 CS6 和 JS。

标签: javascriptadobe-indesign

解决方案


这应该让你开始:

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
}

要知道的一件事是页面外的文本框架(在粘贴板上)会导致此脚本出错,因此您需要尝试/捕获它。但这是一般的想法。这在 CC 中也有效,但在 CS 中没有“parentPage”,所以这可能需要解决。


推荐阅读