Thanks for coming to InDesignSecrets.com, the world's #1 resource for all things InDesign!

Automate GREP Find/Change in InDesign with ChainGREP

Editor’s note: Previously, we shared the news about ChainGREP, a great script that allows you to save shareable custom sets of GREP queries as scripts. This is a follow-up post by the author of that script, to fully explain how it works.

Making GREP easier to use, more flexible and efficient

For most folks, walking 20 feet (6 meters) takes no effort at all. But imagine trying to jump that same distance in one leap. A lot harder, right? It would take a lot of training, and most of us would still never get anywhere near that. Using GREP is very similar. A GREP newbie can sometimes accomplish the same thing as a GREP master by breaking a task into several small steps. That was the first idea behind ChainGREP: to use several simple GREP replacements and execute them one after the other to do the work of a single complex GREP.

Also, when your GREP Find/Change is composed of several independent operations, you can use them interchangeably, making different combinations to accomplish different tasks.

The only problem is when you need to run the same Find/Change operation often, it’s tedious and inefficient to select and execute several queries again and again. To string queries together and run them all, you could use the FindChangeByList script that comes with InDesign, but it is not very user-friendly and hard for most folks to master.

We need a script to the rescue!

Running different queries in a row is a great job for a script. However, like GREP mastery, scripting is a skill that not everyone possesses. So I wrote a script called ChainGREP.jsx that allows you to create your own new scripts that run several GREP queries in a row. And you don’t need to know anything about scripting to use ChainGREP!

How to use ChainGREP

1. Create queries

The first and most important step is to save the individual GREP queries in the Find/Change dialog box. To do this, create the GREP query (including any desired format settings), and save it by clicking on the hard disk icon. Give your query a name that clearly describes what it does. You will need it later for selecting the query.

ChainGREP save GREP query

2. Download the script

After downloading the script, you need to install it. If you need instructions, read this detailed installation guide. As a brief reminder: open the Scripts panel, right-click on the User folder and select Reveal in Finder/Explorer, then copy script to folder Scripts panel and you’re good to go.

3. Run the script

Double-click the ChainGREP script in the Scripts panel and a dialog box appears, showing all your saved GREP queries.

chaingGREP Dialog Comment

Your entire list of queries can be stored and run in one script. But it’s more likely that you’ll only want to run a selection of queries, one after the other. To do this, use Remove from List to delete queries from the selection. Then, put the queries in the order you want them to run with the Up or Down buttons.

Next, set the scope for the new script in Scope of Find/Change. In most cases, searching through the document is a good choice.

Then enter a name for the script.

Finally, click Save List and the new script is saved in the FindChangeScripts subfolder, which is created next to the script.

script panel

Unfortunately, the script does not always appear automatically in InDesign CC; sometimes you have to close and reopen the Scripts panel. Then the new script will appear and you can double-click it to run it.

Your scripts are portable

In the script, the queries are saved with all settings. This means you can also move the script to another location or use it on another computer where the queries are not installed. This also means that if the original GREP query is changed, the script must be re-created.

Write your own script

If you would rather write your own script, you can open the script and analyze the code – it is all open source. If you can read German, I recommend my book InDesign automatisieren, which contains a comprehensive overview of Find/Change operations with GREP. Currently, there is no English version of the book.

Finally, many thanks to Peter Kahrel, who gave me the idea for this script with his script GREP query manager.

Gregor Fellenz

Gregor Fellenz

Gregor is developing InDesign Workflows at www.publishingx.de. For his passion for layout automation, he dives deep into InDesign scripting and XML. He is the author of InDesign automatisieren published by dPunkt. After work, he loves to spend time with his partner and kids.
Gregor Fellenz

Latest posts by Gregor Fellenz (see all)

Tags
Related Articles
Comments

8 Comments on “Automate GREP Find/Change in InDesign with ChainGREP

  1. Hey Gregor, many thanks for creating and sharing this with us. It is indeed a good script. How about adding the “Text Find/Change” functionality to it. That way the script will be more beautiful and effective.

    Anyway thanks a lot. The script is now in my favorites folder :)

  2. The fact that a single individual can add useful new features to ID hints at what should be happening with an app that we’re either paying $240 or $600 a year to use. The value of chaining scripts is obvious. The value having multiple replaces for a single search result is almost as obvious.

    And one look at the S&R panel would show how clumsily designed it is. Users are forced to jump through a minefield with a result they don’t want, “Change All,” to get to those they do. And there are few things more tiring than going doing hundreds of search hits, having to use fine motor skills to hit a particular button and only that button.

    When Creative Cloud came out, I hoped for these improvements to come out almost monthly, justifying that subscription cost. I’ve not seen that. We wait a year and a half and get changes that wouldn’t justify a free X.1 update under the old purchase model. More and more, we’re forced to rely on third-party tweaks that may no survive the next major update.

    At the very least, Adobe should cut the monthly fee of ID to the same $10 they charge photographers for Photoshop, an app that does benefit from a continuous improvement cycle.

    • Looks like the script (respectively InDesign as runner of the script) does not have write permissions on the folder it is installed in. Is the script installed in the “User” Folder?

  3. Thanx a million. I used the script of Peter Kahrel until the updates of Indesign made it impossible. When you are working with multiple book documents it’s a nice thing to have. I’m glad there is a “successor”.

  4. Does your book “InDesign automatisieren” will be translated in English in the future? It’s exactly what I’m looking for.

Leave a Reply

Your email address will not be published. Required fields are marked *