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

Scripted Style Lists

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) {
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.

Mike Rankin

Mike Rankin

Editor in Chief of, InDesign Magazine, and Author of courses on InDesign and Illustrator. Husband. Dad. Dog walker.
Mike Rankin

Latest posts by Mike Rankin (see all)

  • - November 30, -0001
Related Articles

15 Comments on “Scripted Style Lists

  1. Excellent post, Mike! You covered all the important points I think. I agree, it is amazing to see scripters just sort of casually drop these amazing, time-saving scripts around. There are a number of these in various threads on our InDesign forums, too.

    One tip to add: The fastest way to get to the right folder to save the script to is to right-click on any script in InDesign’s Scripts panel and choose Reveal in Explorer (for a PC) or Reveal in Finder (for a Mac). You’re brought to the correct folder in your operating system. Put the new scripts in there.

    Or you can create your own folders in that Script Panel folder for your own scripts. I put mine in a “MyScripts” subfolder. Easy to distinguish the ones that come with ID vs. ones you’ve added that way.

  2. I thought the same thing as Branislav, but then I thought: Hey, sometimes it’s cool to teach people to open the hood (bonnet) of their car and look inside. They do not have to learn how to write scripts, but it is good to see the script and learn what to do with it.

    Then I thought: Nah, let ’em download it. :)

    Here you got:

    (If you get a “.txt” at the end of the file, delete that part of the name. It should end as .jsx)

  3. Aww, you guys are a couple of softies. There will be times when there’s no DL link and folks gotta know what to do. Just yesterday I got an email from someone with script code they found in a forum that they couldn’t get to work.

  4. G’day Folks

    Thanking you so very much for posting this and please pass on my thanks to Mr Saunders too.

    I’ve been desperately hunting for something like this a for a very, very long time. It’s going to save me hours every week.

    Thanks n cheers, Gobit

    PS: Thanks too for both the under-the-bonnet look and the URL :-)

  5. If you have one script, it is easier to “recycle” it to do something similar than to write another one from scratch. I had a similar need for paragraph styles and hacked a similar script … later on I needed something to list the swatches with their color components, so this paragraph styles script got “recycled” to do the swatches.

  6. I don’t know if I’m just stupid or maybe it only works in CS5.5 (I have CS5). When I place my cursor in a text box and run the script nothing happens. Just for good measure I downloaded the one that was posted above and still nothing. No error…nothing. Cursor just sits there. I’d love to get this to work.

  7. Gary, don’t feel stupid; I know it can be really frustrating when a script isn’t working. That’s why I wrote this post.

    It’s not necessary to have your cursor in a text frame. The script should do its thing without anything selected. I just checked and confirmed it works in CS5 too. Can you try running it from ESTK following the instructions above?

  8. G’day Gary

    When I first ran the script I too thought nothing had happened and was really scratching my head after running it for the third time without seeing anything.

    However, after zooming out quite a bit I found the text box the script had created sitting on the pasteboard quite way to the left of the first page of the document. In fact I found three of them quietly hiding there. The script had run so quick and smooth I hadn’t even noticed. :-)

    Cheers, Gobit

  9. Thanks to everyone who responded. Turns out it does work after all with just a couple oddities:

    On a multi-page document, it always puts the list on the first page, regardless of what page I’m viewing. Also it seems to put it on the pasteboard to the left of the page.

    When I am viewing the 1st page and run the scrip, I have to refresh the page for the list to appear. Odd, but at least now I know and it does work quite nicely. Thanks again all.

  10. HI, is there a way to make this only create the styles in use in the current file ,or all styles in the current file, with a toggle (so you can choose how you want it generated)? Sometimes I really want to know everything that’s available (like in a template) and sometimes I only want to see the examples and names of the styles that someone has actually used.

  11. It works in CS6!

    Nice job. Thank you.

    Now, if I could find a script that lists all the style definitions, too.

Leave a Reply

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