Dispersion Design

< Back

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.

InDesign Find/Change dialog box

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 SettingJavaScript command
Reset Find preferencesapp.findGrepPreferences = NothingEnum.nothing;
Find what:app.findGrepPreferences.findWhat = 'lead';
Find Format
+ size: 12 pt
app.findGrepPreferences.pointSize = 12;
Reset Change preferencesapp.changeGrepPreferences = NothingEnum.nothing;
Change to:app.changeGrepPreferences.changeTo = 'gold';
Change Format:
Paragraph Style: Heading 1
var styles = app.activeDocument.paragraphStyles;
var style = styles.item('Heading 1');
app.changeGrepPreferences.appliedParagraphStyle = style;
Change Allvar selection = app.activeDocument.selection.sel[0];
selection.parentStory.changeGrep();