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.


    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.

    //remove leftover attributes
    var flag = true;
    catch(e){flag = false;};
    //remove leftover processing instructions
    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();

    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];
    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.


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

  1. I just found your “Removing XML” script and it works perfectly!!! Did you know that when you use Data Merge, InDesign automatically puts everything into tag markers and puts them into the XML structure? I like clean InDesign files and having all those markers and tags in the files when we don’t use them for anything doesn’t make sense. So many thanks for sharing!!!

    Liked by 1 person

    • Glad it helped. My company uses XML for almost every InDesign file, and sometimes it’s a pain to work with. It’s so much easier to strip it out with a script than to try and do it manually.


Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s