Indesign Javascript: List and demo all paragraph styles
A script that fills the selected text frame with paragraphs, each containing one of the paragraph styles' name in that same paragraph style.
Posted on 2010-08-06 14:56 by Jørn Støylen [permalink]
In the process of standardizing the paragraph styles of an new publication I had designed at my workplace, I wanted to get an overview over the document’s paragraph styles. My starting point was the Indesign document of one of our other publications, since this saves a lot of setting up things all over again. But I had only changed a few of the styles – only the ones I needed for the dummy we presented to the customer.
So instead of doing this manually, which would probably take me a few hours, I spent a few hours programming a small Javascript which does the job automatically. (If I were more proficient in Indesign’s DOM, I probably could have done it in less than an hour.)
I have only tested this in CS3 and CS4, but I have no reason to suspect it won’t work in CS5 also.
Usage:
- In an Indesign document, select a text frame (typically an empty one, although the script will just add paragraphs at the end of any content therein) with the Selection Tool (not the Text Tool).
- Either save the script to a file and load it in Indesign’s Scripts panel and run it from there, or run it from Extendscript Toolkit by loading/pasting it there, targeting Indesign in the dropdown menu in the top of the code window and run it.
After a few seconds of deliberation, Indesign should fill the text frame with paragraphs containing all your different paragraph styles and their respective names.
doIt();
function doIt() {
var doc = app.activeDocument;
if ( app.documents.length > 0 &&
app.selection.length 1 ) {
var tf = doc.selection[0];
if (tf.toString() = "[object TextFrame]") {
var story = tf.parentStory;
}
var style = doc.paragraphStyles.lastItem();
style = doc.paragraphStyles.nextItem(style);
var style = null;
do {
if (style == null) {
style = doc.paragraphStyles.firstItem();
}
else {
style = doc.paragraphStyles.nextItem(style);
}
story.insertionPoints.item(-1).contents = "\r"+style.name;
story.paragraphs.lastItem().applyParagraphStyle(style);
} while (style!=doc.paragraphStyles.lastItem());
}
else {
alert("Please select a text frame with the Selection Tool (not the Type Tool) before running this script.");
}
}
Comments closed
Commenting is closed for this article.

