Your First Practical InDesign Automation: Opening and Closing Multiple Files

0. Who This Article Is For

This is the second article in the beginner automation series.

It assumes you already know how to run a simple .jsx file in InDesign.
(If not, please read the first article in this series first.)

You do not need advanced JavaScript knowledge.

If you work with InDesign Books and regularly open multiple documents for checking or review, this article is for you.

The goal is simple:

Remove repeated friction.


1. The Problem: Opening 15 Files Manually

Imagine this situation:

  • One Book file

  • 15 InDesign documents inside

  • 5 language versions

After translation, you need to open every file to check layout, overset, images, or styles.

Opening 15 files once is not a problem.
Opening them 100 times over a project lifecycle is.

The action itself is trivial.
The repetition is not.


2. Why This Doesn’t Scale

Automation is not about complexity.

It is about repetition.

Opening files manually:

  • Click

  • Wait

  • Click

  • Wait

This pattern seems small, but in multilingual workflows it multiplies quickly.

Scaling means removing actions that do not require judgment.

Opening and closing files require no judgment.
Therefore, they are good candidates for automation.


3. Minimal Script Example

Before using these scripts, make sure:

  • InDesign is open

  • A Book file is open

(You already know how to run a .jsx file from the previous beginner article.)


3.1 Open All Documents in the Active Book

#target indesign
// Open all documents in the active Book (.indb)
//
// Beginner version:
// - No GUI (no dialogs)
// - Minimal guards
// - No heavy error handling
// - No OS-specific path logic

(function () {
if (app.books.length === 0) {
alert("No Book is currently open.\nOpen a .indb file first, then run this script.");
return;
}

var book = app.activeBook;
var contents = book.bookContents;

if (contents.length === 0) {
alert("The active Book has no documents.");
return;
}

for (var i = 0; i < contents.length; i++) {
// Opens the INDD referenced by the Book content.
// If the document is already open, InDesign may show a notice or simply activate it.
app.open(contents[i].fullName);
}

alert("Completed.\nOpened: " + contents.length + " document(s).");
})();

This script:

  • Assumes one Book is active

  • Loops through all bookContents

  • Opens each file

Nothing more.


3.2 Close All Open Documents (and Books)

#target indesign // Close all open documents (without forcing a save) // Optional: close all open Books as well // // Beginner version: // - Does NOT force saving (SaveOptions.NO) // - Skips unsaved documents (new/dirty) to avoid risky loss // - Loops backward to avoid index shifting while closing (function () { if (app.documents.length === 0 && app.books.length === 0) { alert("Nothing to close.\nNo documents or Books are currently open."); return; } // Close documents (backward loop is important) var docs = app.documents; var closedDocs = 0; var skippedDocs = 0; for (var i = docs.length - 1; i >= 0; i--) { var doc = docs[i]; // doc.saved is true when the document has no unsaved changes. // We only close "clean" documents in this beginner example. if (doc.saved) { doc.close(SaveOptions.NO); closedDocs++; } else { skippedDocs++; } } // Optional: close Books too (also without forcing a save) var closeBooks = confirm("Documents closed: " + closedDocs + "\nSkipped (unsaved/dirty): " + skippedDocs + "\n\nDo you want to close all open Books as well?"); var closedBooks = 0; if (closeBooks) { // Close all open Books (backward loop to be safe) for (var b = app.books.length - 1; b >= 0; b--) { app.books[b].close(SaveOptions.NO); closedBooks++; } alert("Completed.\nClosed Books: " + closedBooks); } else { alert("Completed.\nClosed Docs: " + closedDocs + "\nSkipped Docs: " + skippedDocs); } })();

Why loop backward?

When closing items inside a collection, the index changes.

If you close from the front:

  • You close item 0

  • What used to be item 1 becomes item 0

  • The loop skips one

Looping backward avoids this.


4. What This Teaches You

Even this small script introduces core concepts:

  • app

  • books

  • documents

  • loops

  • conditions

You do not need complex logic to start automating.

You need to identify repetition.


5. Where This Leads

From here, you can extend the idea:

  • Open only files matching a condition

  • Skip certain chapters

  • Run a check automatically after opening

  • Combine open → process → close

This is how automation grows.

Not by jumping to complex tools.

But by removing friction, step by step.

Popular Posts