A Visual Guide to Scripting Find/Change
2012-04-12
Introduction
Writing your own scripts for Adobe® InDesign® can dramatically improve your productivity. When working with the JavaScript API for InDesign, it is sometimes difficult to find the correct command to perform the desired action.
The following article will present the common JavaScript commands needed when writing scripts involving performing Find/Change operations in InDesign.
Visualizing the Find/Change Dialog
The diagram below shows the InDesign Find/Change dialog box with the GREP tab selected. A few common settings have been entered into the dialog box and the equivalent JavaScript commands for these settings are annotated on the diagram.
Table of JavaScript Find/Change Options
The following table show the same Find/Change commands as the diagram above. You should be able to copy and paste the commands from this table to help you develop your own scripts.
Find/Change Setting | JavaScript command |
---|---|
Reset Find preferences | app.findGrepPreferences =
NothingEnum.nothing; |
Find what: | app.findGrepPreferences.findWhat =
'lead'; |
Find Format + size: 12 pt | app.findGrepPreferences.pointSize =
12; |
Reset Change preferences | app.changeGrepPreferences
= NothingEnum.nothing; |
Change to: | app.changeGrepPreferences.changeTo =
'gold'; |
Change Format: Paragraph Style: Heading 1 | var styles = app.activeDocument.paragraphStyles; |
Change All | var selection =
app.activeDocument.selection.sel[0]; |