A Script for Counting List Items
Here’s a nifty little script that gives InDesign the ability to find the number of paragraphs set in a certain paragraph style and make that number appear in your document. It’s great for displaying the number of list items, steps in a series of instructions, etc.
Here’s a potential use case. Say you have a bunch of lists with headings, like so:
The list items are styled with a paragraph style called Steps and the title is styled with a paragraph style called Header.
In the title you’d also like to include the number of items in the list, like so:
The script saves you the effort of checking the number of steps and typing it in the title. It works by looking for a series of numbered paragraphs with a paragraph style called “Steps” applied to them.
It then checks the number of the last paragraph in the series (in this case 10), and inserts that number in a text string at the end of the preceding paragraph styled with Header. If the number is already there, the script will update it to match the current last number in the Steps paragraphs.
You don’t need to have anything selected for the script to work. It will find all instances of the styles and apply the correct numbering.
Ah, but what if you don’t use styles called Steps and Header? No problem! Just open the script in a text editor and Find/Change all instances of the style names to whatever you use in your InDesign document.
Note that the name of the style applied to the steps or list items is what will appear in parentheses in the header. Also note that in the example below, the formatting of the text inserted by the script comes from a nested style in the Header paragraph style. The script doesn’t apply any formatting.