is now part of CreativePro.com!

Automate GREP Find/Change in InDesign with ChainGREP

33 1

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!

More after the jump! Continue reading below
Free and Premium members see fewer ads! Sign up and log-in today.

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.

  • Masood Ahmad says:

    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 :)

  • 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.

  • Dhafir Photo says:

    It’s don’t work, and this warning appears:
    Could not read Query-Files in Folder

    • 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?

      • Crystal Bradfield says:

        I am having the same problem. It brings up the ‘Save GREP Queries’ just fine and shows me all my saved queries, but when I hit ‘Save List’ I get the error. Here is where my script is located: /Applications/Adobe InDesign CC 2018/Scripts/Scripts Panel

      • @Crystal Bradfield Your Script is in the Application Folder. Install it in the User Folder.

  • Ewald says:

    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”.

  • meena says:

    thanks thanks thanks
    useful script in script user

  • gmalvestiti says:

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

  • Bren says:

    Fantastic script, thank you very much, this will be so useful.

  • Nilesh Parmar says:

    This script is great, thank you.

  • The script is now avalable in german and japanese: https://www.publishingx.de/download/chain-grep/

    jp credits to @Yo_Yu_You

  • Dmitry Chernysh says:

    Hi Gregor,

    Thanks for an amazing script.

    My only question is whether it is possible to run the chain on multiple selected stories. That would be a lifesaver.

    Thanks heaps!

  • Nancy Mueller says:

    I’ve just downloaded the chainGREP script and upon running it I get this error: Cannot write at [/Applications/Adobe%20InDesign%20CC%202018/Scripts/Scripts%20Panel/FindChangeScripts] Check permissions! How do I fix this please?

  • Gary Muddyman says:

    Hello, I’m having problems running the scrip. When I try to run it I have an error pop-up saying “Could not read Query-Files in Folder [~/AppData/Roaming/Adobe/InDesign/Version 14.0/en_AE/Find-Change Queries/GREP]”. If I go to the destination I have installed the ME version, so my path should be “…/Version 14.0-ME/…”. Is there a way to change where the script looks for queries? I have found a workaround to make it work (copying my 14.0-ME folder and delete the “-ME” part), but I was wondering if could be possible to change that behavior. Thank you very much in advance and for the script

  • Walt Sterdan says:

    Great script and a real time-saver, however I’m having an encoding issue when I run it. I’m using it to do some translation work and although the script itself and the script it generates are UTF-8, when InDesign reads the list of S&Rs it’s reading it as if it’s ASCII and all accented characters are being converted to two characters. Is there a setting in Indesign somewhere, or somewhere in the saved script that would allow me to force InDesign to keep the UTF-8 characters as it reads in the search/replace strings? I’m currently testing it with CC2019.

    • It looks like, higher Unicode Code Points are wrongly saved from InDesign. For example +UF0000 from Supplementary Private Use Area-A is saved as and even in the UI not usable.
      I don’t have a quick solution, besides Adobe fixes this issue. But you can try to use \x{Unicode} to prepare your GREP-Expression.

  • Walt Sterdan says:

    Thanks for the reply, much appreciated. I’ll take a look a using the codes for the character, but my confusion is that, as mentioned, the file that your script saves is UTF-8 and the characters are all correct. It’s only when the script is run that it loads in the UTF-8 file and replaces the non-ascii characters with ascii character pairs. On the on hand, it’s not hard to search and replace the characters with the correct ones after running the script, but many of the later scripts rely on the first half having been done correctly, which causes many of them to fail.

    Thanks again for an excellent script. I’ll let you know if I can come up with a solution.

  • Amber Bordelon says:

    Hello! I love this script, but I am running into an issue: Not all of my saved custom queries appear in the dialog box. I cannot figure out what causes some of them to appear and others not to. Do you have any advice?

    • Erica Gamet says:

      I haven’t had that issue with it (but haven’t run it with CC2019 yet). What version of InDesign are you using? Gregor Fellenz is the creator of the script…you might try contacting him through his website: https://www.publishingx.de/kontakt/

    • Gregor Fellenz says:

      The script excpects the Query-Files in the program and user folder.
      The folders depending on your version, language und username:

      program folder is sth. like

      /Applications/Adobe InDesign CC 2019/Presets/Find-Change Queries/GREP/LANGUAGE

      the user folder is sth. like

      /Users/USERNAME/Library/Preferences/Adobe InDesign/Version 14.0/LANGUAGE/Find-Change Queries/GREP

      Can you check:

      1. Does the missing XML-Query-File exists in the folders?
      2. Is one folder ignored?

      It’s possible that there is a wrong configuration on your machine.
      Which version and platform do you use?
      Can you send me a Query which does not load?

  • Amber Bordelon says:

    Thank you so much for the quick response!

    I am still in CC 2018, but I could run it in 2019 too if you want more info on later editions. Most of the greps I was using were test greps, therefore very simple ones. For example, I tried making one to convert numbers into numbers with soft returns. That one didn’t show up. I did notice that if I save it with a custom name, it never shows up, but with the default name the program assigns to it, it does. That could get confusing though, because I wont remember ‘Query 1″ in six months, but I will understand “Numbers with Soft Returns”.

    I looked in both folders, and oddly enough neither one had the custom greps I made. It only contained the defaults. Do you think this has to do with it being a CC program or is it just the edition?

    • The script can only read and process GREP-Queries (XML-Files) from those two standard folders. So from my/script perspective: As long as the numer of XML-Files equals the Script UI everything works as expected. Is that correct?

      I guess there is permission error on your machine. Your newly added Queries should show up in the user folder. If the Query-Files are not there, probably you cannot see them in the Search/Replace-Dialog either?

  • Gary Oliver says:

    Script no longer works properly for me using InDesign 2020. I need it so much, too. :(

    • Mike Rankin Mike Rankin says:

      I just tried it in InDesign 2021 and it’s working. Have you used it successfully in the past? Maybe double-check that you’re following all the steps to save queries, arrange them into a chain, etc.

    • Gregor Fellenz says:

      The script should work in 2020 and 2021. Please check the location. The script needs to be installed in the user script folder (not the application script folder).

  • >