javascript - 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 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”,所以这可能需要解决。
推荐阅读
- javascript - 如何在 react native 中创建自定义动画浮动标签 TextInput?
- ionic-framework - 离子和电容器 - 闪屏响应性(闪屏图像被拉伸)
- google-play - Apple Store 和 Google Play Store 收取多少佣金?
- python - 从代理向 SNMP 表发送数据
- java - 向 Azure 事件中心上的主题发送事件时有 30-35 秒的延迟
- google-apps-script - 当不是每一行都被填满时进行分组过滤
- reactjs - 提交时返回未定义的反应挂钩表单
- javascript - nodejs express 应用程序中的高堆使用率
- r - 在R中按元素拆分和组合大量列表
- java - 在服务器上运行spring应用并离开(nohup错误)