Scripted Style Lists
Did you ever want a list of a document's paragraph styles where each style name appears in the style's formatting? Here's a script that does just that, along with some...

I never cease to be amazed by expert InDesign scripters. They can do things we mere mortals can only dream of and are often quite generous with their talents. Look around and you might find a great InDesign script in a forum post, blog comment, or even Facebook. Case in point: I recently came across a online posting where the estimable Dave Saunders had casually offered up some scriptastic magic to a friend in need.
The script Dave posted creates a list of paragraph styles where each style name appears in the formatting of the style. It’s like a quick visual guide to a document’s paragraph styles.
The list appears in a text frame on the pasteboard to the left of the first page in the document.
Dave has kindly said it was OK for me to re-post the code, so here it is:
//DESCRIPTION: List paragraph styles in their style
(function() {
if (app.documents.length > 0) {
processDocument(app.documents[0]);
}
function processDocument(aDoc) {
var page = aDoc.pages[0];
var bounds = page.bounds;
var theTF = page.textFrames.add({geometricBounds: bounds});
var theStory = theTF.parentStory;
theTF.move(undefined, [bounds[1] - bounds[3], 0]);
var paraStyles = aDoc.allParagraphStyles.sort();
for (var j = 0; paraStyles.length > j; j++) {
theStory.insertionPoints[-1].contents = paraStyles[j].name;
theStory.paragraphs[-1].appliedParagraphStyle = paraStyles[j];
theStory.insertionPoints[-1].contents = "\r";
}
}
}())
Not only is the script cool for what it does, but we can also use it to illustrate how to grab JavaScript code and put it into a form that InDesign can use. Here are two methods:
Method 1: Use a text editor
Copy the code and paste it into a text editor. Save it as a plain text file, not RTF or anything else that retains formatting. If you’re on a Mac, you can paste the script code into TextEdit. Be sure you choose Format > Make Plain Text, and change the file extension to .jsx when you save it.
Method 2: Use ExtendScript Toolkit (ESTK)
ESTK is a development and debugging tool for JavaScript scripts that comes with InDesign and other Adobe Creative Suite applications.
First, make sure InDesign is running. Then launch ESTK. A new empty script document will open.
Choose InDesign as the target application from the pop-up menu.
Paste in the script code.
Make sure you have an InDesign document open and then press the green Play button to run the script. Voila, you get a styled style list.
With either method, you can get the script to appear in your InDesign Scripts panel by saving it into the Scripts Panel folder.
When you run this script, be mindful that Keep Options like Start in New Column will still function in the list. So if the list is truncated and overset, this is probably the reason. To fix the list, make a local override. Put your cursor in the text frame, select all, and choose Keep Options from the Control Panel menu (or press cmd+opt+k/ctrl+alt+k). Then select Start Paragraph: Anywhere in the dialog box.
Now one more thing: notice how the script code above looks different from the rest of the blog post? It’s using the HTML tag <pre>, which sets the text in a fixed width font and preserves spaces and line breaks. If you copy script code that’s been formatted, you have to be sure that no character substitution has occurred. Just a single bad character will stop a script from working. For example, if I paste the code into InDesign, it automatically converts the straight quotes to curly quotes because I have my preferences set to Use Typographer’s Quotes.
If I then take this code and paste it into ESTK or a text editor, the script gets stuck on the first curly quote.
So if you’re copying and pasting script code and it’s not working, first make sure that you copied all the code (and nothing but the code), and then check that no characters got switched in the process.
Again, thank you Dave for this great and useful script. And to my fellow code foragers, go forth and copy and paste code with confidence.
This article was last modified on December 21, 2021
This article was first published on September 23, 2011