// you’re reading...

Internet

Using InDesign Scripting To Find And Change Text

Adobe InDesign has long offered users the option of automating their workflows through scripting. Although scripts may be writing in AppleScript (Macintosh only) or VBScript (Windows only), the most satisfactory scripting language is the cross-platform, and very widely used, JavaScript. One of the simplest and yet most useful operations that can be accomplished using scripting is the automation of Find/Change. InDesign’s Find/Change feature is one of the program’s most powerful features and it is one of those features which can be fully automated by scripting. In fact, you can achieve a lot more through scripting than you can by manually performing a Find/Change operation.

There are three commands in the InDesign scripting framework for performing Find/Change operations: findText(), findGrep() and findGlyph(). A good deal can be accomplished using the straightforward findText() command. However, if you need to make fairly complex changes, and if you have the time and patience to find the right regular expression, you can use the findGrep() command which is designed for performing searches for regular expressions.

To script a Find/Change operation, you first of all need to set up the preferences that will be used when performing the Find or Change. Firstly, you set the properties of the findChangeTextOptions object: parameters include caseSensitive, wholeWord, ignoreHiddenLayers and ignoreMasterPages. Next, you set up your findTextPreferences and changeTextPreferences parameters, the most important of which are findWhat and changeTo, respectively. It is also usually a good idea to clear out any preferences that may still be in play from a previous search. This is done by setting both the findTextPreferences and changeTextPreferences objects to nothing, using the commands: app.findTextPreferences = NothingEnum.nothing and app.changeTextPreferences = NothingEnum.nothing.

Just as when performing Find/Change manually, the findTextPreferences and changeTextPreferences objects offer all of the formatting parameters normally available with text objects.

One of the practical exercises which we give to students attending our InDesign scripting courses is to create a script which searches for the name of a company within a document, changes the format of the text to look like a regular web hyperlink (blue, bold, underlined) and then makes it a hyperlink. To change the format of the text, we simply use the appropriate properties of the changeTextPreferences object, such as fillColor, fontStyle and underline.

The writer of this article is a trainer and developer with an independent computer training company offering Adobe InDesign Classes as well as Photoshop training at their central London training centre.

Tags: , , , ,

Discussion

No comments for “Using InDesign Scripting To Find And Change Text”

Post a comment