Chaining GREP Queries
We’ve seen that it is often preferable, and sometimes even necessary, to use more than one expression to achieve something. But unfortunately it is not possible in GREP’s interface to chain two or more expressions, so you may find yourself running saved queries in succession.
However, you can chain queries using a simple script, so that any number of queries can be executed by running a single script. Here’s an example. Let’s say you saved the three queries needed to add thousand separators in three queries and that you called those queries thousand_1, thousand_2, and thousand_3. The text of the script to execute the three queries is as follows:
app.loadFindChangeQuery ("thousand-1", SearchModes.grepSearch);app.activeDocument.changeGrep();app.loadFindChangeQuery ("thousand-2", SearchModes.grepSearch);app.activeDocument.changeGrep();app.loadFindChangeQuery ("thousand-3", SearchModes.grepSearch);app.activeDocument.changeGrep();
Save these lines in a plain text file, calling it, say, thousand_separators.jsx (the name itself is not important, but for the file extension you must use jsx. Place the script file in your script directory. If you don’t know where that is, you can locate it as follows:
In InDesign, open the Scripts panel (Window → Utilities → Scripts).
Select the User folder in the panel, then click the flyout button
(see Figure 8).Select “Reveal in ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access