InDesign Scripts I’ve Found to Be Useful

I use InDesign a lot for my work. One of my responsibilities is to clean up InDesign files that have been created by someone else. In doing so, I’ve realized that while many graphic designers can do amazing things with Photoshop and Illustrator, they’re not as comfortable using the features that InDesign has. This leads to really messy files that, at times, have been easier to rebuild than to clean up.

With that introduction, I present to you a list of some quick and easy javascripts that help with cleaning up an InDesign file:

  1. Removing style overrides
    Paragraph and character styles are my best friends in InDesign. They provide a clean and consistent look through the entire document. Occasionally, I need to adjust tracking or kerning, maybe even the spacing around a paragraph, but nothing makes my life easier than starting with clean styles.

    app.activeDocument.stories.everyItem().clearOverrides();

    This one-line script wipes away all overrides to my styles and gives me a clean document to start from. It’s also become really handy in showing designers what proper styling can do for their designs. (If you ever want to freak out an inexperienced designer, show him/her what their file looks like with no style overrides. They see the benefit of proper styling pretty quickly.)

  2. Removing XML
    For a long time my company used XML as a way of archiving the text for our printed documents. It was a convenient way to store the files because of the small size and the ability to import the XML into InDesign. A couple of years ago we switched over to a new production system that worked primarily with the InDesign files themselves. As we started transferring our files over to the new system, we realized that this new software didn’t like our particular brand of XML and we were required to strip the XML from the document before we could properly archive it in the new system. Doing that manually, for hundreds (if not thousands) of documents wasn’t feasible.

    app.activeDocument.xmlElements[0].xmlElements.everyItem().untag();
    //remove leftover attributes
    var flag = true;
    while(flag){
    try{
    app.activeDocument.xmlElements.item(0).xmlAttributes.firstItem().remove();
    }
    catch(e){flag = false;};
    }
    //remove leftover processing instructions
    try{
    app.activeDocument.xmlInstructions[0].remove();
    }
    catch(e){};app.activeDocument.deleteUnusedTags();
    var myRoot = app.activeDocument.xmlTags[0].name;
    app.activeDocument.xmlTags.itemByName(myRoot).name = "Root";
    //remove leftover text in root element
    var tempRect = app.documents[0].rectangles.add();
    tempRect.markup(app.documents[0].xmlElements[0]);
    tempRect.remove();

    This will go through and untag all of the XML, remove the tags, and clean up any leftover items that couldn’t be placed into the document. (The rectangle bit at the end catches a bug in InDesign that causes some of the XML to find its way into Root element when it’s untagged)

  3. Accepting all changes
    Track changes is a wonderful tool for editors. It lets them see exactly who has done what to their text. The problem is that often editors don’t go through and accept all changes before signing off on the text, which means all those bits of text are still floating around somewhere in the InDesign file.

    var s = app.activeDocument.stories;
    var c;
    for(var i = 0; i < s.length; i++){
    for(var j = 0; j < s[i].changes.length; j++){
    c = s[i].changes[j];
    c.accept();
    }
    s[i].trackChanges = false;
    }

    This script goes through each story in the document and accepts all the changes before turning off the track changes feature. It’s a nice final step before archiving or sending to press.

These are few scripts that I’ve written and use in my work. If you’re new to scripting, I’d recommend browsing through the site list below. I’ve used each of these sites in developing scripts. There are some truly fantastic resources available online.

Advertisements

2 thoughts on “InDesign Scripts I’ve Found to Be Useful

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s