A GREP query manager

If you use GREP queries a lot, it's easy to lose track of what's in which query. The query-manager script displays an overview of all GREP queries, showing each query's name, find expression, and change expression. The script aims to address various shortcomings of InDesign's possibilities to manage queries, such as InDesign's inability to chain existing queries and to edit GREP expressions conveniently. The script is a panel, so you can keep it open and work in InDesign.

Note: For a much simpler script, one that simply runs selected queries, see here.

The script displays the contents of all GREP queries in the current user's folder as shown in the screenshot. It looks in the user's folder only. Information is displayed in three columns. Query: the name of the query on disk, i.e. the name under which you originally saved the query; Find what: the contents of the Find what field in the Find/Change folder; Change to: the contents of the Change to field in the Find/Change folder. If a field has no contents, the script shows that by printing ---- for clarity. The functions of the buttons are explained below.

The script's window can be resized; the width of the columns can be changed in the normal way, too: click in the header row on a column separator and drag it left or right. (You'll notice that if you've resized the columns and then resize the window, the columns snap back to their original widths; this is a bug in the script language, not the script.)

GREP queries overview

The script's functionality is contained in the panels on the right-hand side of the script's window.


A chain is a collection of two or more queries. To create a chain, select some queries in the main window, then press save query icon. Provide a name and press OK:

GREP queries new chain

Any number of queries can be grouped in a chain. When you execute a chain, all queries in the chain are processed in the order in which they occur in the list on the left.

Chains are small files which are stored in the user's Grep query folder, using the extension .qrpq. To delete a chain, select it in the dropdown and press delete chain -- this deletes just the chain, not the queries.

When you select a stored chain from the dropdown, the queries defined in it are selected in the list.

Select a search target

You can target the familiar All documents, Document, Selection, and Story. In addition, if you have a Book file open, you can process all book contents. (To target selected book documents, open them and target All documents.) Finally, you can target folders. After selecting Folder and pressing Execute queries, you can select a folder in a dialog. Warning: targetting folders and books can affect many documents. Always make a copy of your documents or zip them up before modifying them when you target a folder or a book.

Executing queries

Press Execute queries to execute the queries selected in the list. (These could have been chosen manually or by picking a chain from the dropdown.) Queries are executed in the order in which you see them in the list. If you want to change the order of execution, you'll have to rename the queries (using the Rename query button in the bottom panel).

Because the script executes queries using InDesign's Find/Change, all formatting defined in queries is respected and applied, even though you can't see that formatting in the script's interface. But open the Find/Change dialog and you can see the query's format settings in the Find Format and Change Format panels.

Collect found items

Rather than executing the selected queries, you can instead collect whatever the query or queries match and print the found results in a new file. Your document is not changed at all. To collect the found items, check Collect found items. The found items are listed in a new document, sorted, and any duplicates and formatting are removed. To leave formatting intact, check Include format.

Add page numbers

You can opt to add the numbers of the pages where each query was found (thanks to Laurent Tournier for this idea).

Manipulating queries

The fourth panel offers some options to manipulate a query. The first two buttons in the panel (Edit query in GREP editor and Query to F/C dialog) are disabled when more than one query is selected, as in the screenshot.

Edit query

Press Edit query in GREP editor to load the Find what part of the query in the GREP editor, which is a separate script. (If the script can't be found the button is disabled; the Grep editor and its icons must be in the same folder as the Grep manager.)

In addition, the script has a simple built-in editor that can be used simply to display a long query that doesn't fit in the list, but also to make changes to the GREP expression. To use this built-in editor, select a query, then press edit grep:

GREP query queries overview

The Find expression is shown in the upper panel, the replace expression in the bottom one. (In CS5.5 and earlier, use the ¶ button to add a new line; this button is not available in CS6 and later.) To copy and paste, right-click in the window and pick Copy or Paste from the context menu. Exit the window either by pressing Save changes or press Cancel to ignore any changes.

Copy selected queries to GREP styles

You can copy the Find what part of queries to GREP styles. To do so, select all the queries you want to copy, then press Query to F/C dialog. The script displays a dialog which lists all the document's paragraph and character styles. Select the paragraph styles to which you want to copy the GREP queries as GREP styles, then select the character style to be used in the GREP style and press OK to commit:

GREP queries overview GREP style

In this example, the GREP expressions in two selected queries (range-phonetic and range-symbol) are copied to the three selected paragraph styles, and the character style specials is assigned to the GREP expressions.

Style groups

Paragraph and character styles in style groups are displayed as follows:

myStylegroupA > mySubgroup1 > myStyle

that is, groups and styles on one line, separated by >.

Managing queries

The last panel has four buttons that can be used to manage queries.

Duplicate/rename/delete queries

You can rename queries (duplicate query) and duplicate them (rename query); the script uses a simple dialog for this:

GREP queries manager: rename GREP query

Queries can also be deleted (delete grep query); you'll be asked to confirm the deletion.

Update list (update grep list)

When you rename, delete, or duplicate a query, the change is reflected in the list in the scripts's interface. But while the script is active it doesn't notice what other programs do in the query folder. So if you rename, copy, or delete queries from outside the script -- probably in InDesign's Find/Change dialog -- the script doesn't notice these changes, and you'll have to update the list yourself; press Update list to do so.

In addition, Update list can be used to reverse the list's sort order.

View/edit a query (view/edit a query icon)

View a long query or edit it it. See above.

Print queries (print overview of queries)

A new document is created and an overview of the selected queries is printed on three lines per query: their name and the content of the Find What and Change To fields. The script adds paragraph and character styles and a few GREP styles to add some code highlighting for clarity. Here's an example:

grep query report

Toggle tooltips (toggle tooltips)

Press the icon to disable or enable the tooltips defined for most buttons and icons.

Version history

10 Oct. 2020: Fixed a bug. When you opted to collect any found items and display their page numbers, the script didn't display anything if any of the found items was on the pasteboard.

14 Aug. 2019: There continued to be problems with the display of the list of queries. It's not entirely clear which OS and/or which InDesign version is responsible; it looks as if it's CS6 on Windows. I now post two versions of the script. First try the script that does not have CS6 in its name. If that one shows garbled content where you'd expect the quries, try the other version.

20 June 2019: Revised some help tips, made some cosmetic changes to the interface. Functionally nothing changed.

11 Dec. 2018: Added a function to the 'Update list' icon. When you click it, the list's sort order is reversed.

8 May 2016: Added code to get around the problem that listboxes don't display in CS6 on Windows 10.

13 Sept. 2014: Fixed a reference problem that could render the GREP editor invisible to the Query manager.

17 May 2012: All icons are now embedded in the script.

23 April 2012: (1) From CS6, the Enter key can be made to work as expected in edit panes; applied to the script. (2) The script created a new window every time it was started. Now it checks if there's a window that can be reused. This should fix some awkward memory and keyboard problems.

24 Jan. 2012: Added the possibility to print an overview of the selected queries. See Print queries for details.

11 Sept. 2011: Fixed problem reading the history file.

10 Sept. 2011: (1) The script now supports style groups (when exporting GREP expressions to GREP styles). (2) It's now possible to select targets: Document, All documents, Selection, Story, Book, or Folder.

6 July 2011: Fixed cosmetic bug which inserted ---- (the script's placeholder for empty fields) in the Change To field in the query file.

9 May 2011: It's now possible to select a character style when you assign queries to GREP styles.

5 May 2011: The metastrings (?#) and (?#T) weren't always removed when expressions were copied to the Find/Change dialog or to GREP styles. Fixed.

20 April 2011: When expressions were saved from the built-in editor, variables ($1, $2, etc.) in the Change To part were not written correctly into the query file. Fixed.

2 April 2011: Incorporated the chaining script in the query manager; added an option to include the page numbers on which the found items occur; changed the query viewer (accessed by right-clicking a query) into a "light editor"; see the text for details.

22 March 2011: Improved performance here and there.

21 March 2011: Added some functions: execute selected queries; duplicate and rename queries. Code rewritten to a large extent.

26 October 2010: More integration with the GREP editor. Queries can now be loaded into the editor straight away.

15 July 2010: Improved interface; improved copying to GREP styles.

Useful script?

Consider making a donation. To make a donation, please press the button below. This is Paypal's payment system; you don't need a Paypal account to use it: you can use several types/brands of credit and debit card.

Peter Kahrel's paypal account

Download scripts The zip contains two scripts, see the update note added 14 Aug. 2019 for details. To install the scripts, just unzip the downloaded zip file in your script folder.

Back to GREP page

Back to main script page

Installing and running scripts

Questions, comments? Get in touch