Skip to main content
Participant
May 6, 2013
Question

How do I run a script on a .indb file?

  • May 6, 2013
  • 2 replies
  • 991 views

How do I run a script on a .indb file? What should I do differently than in running one on a single indd file?

This topic has been closed for replies.

2 replies

Kasyan Servetsky
Legend
May 6, 2013

I do this like so:

var inddFiles = GetFilesFromBook();

for (var i = 0; i < inddFiles.length; i++) {

    inddFile = inddFiles;

    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

    doc = app.open(inddFile);

    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

    // Process document

    doc.close(SaveOptions.YES);

}

function GetFilesFromBook() {

    var bookContent, file,

    activeBook = app.activeBook,

    files = [];

   

    for (var i = 0; i < activeBook.bookContents.length; i++) {

        bookContent = activeBook.bookContents;

        if (bookContent.status != BookContentStatus.MISSING_DOCUMENT) {

            file = new File(bookContent.fullName);

            files.push(file);

        }

    }

   

    return files;

}

Here is the whole script that you can use as example.

Peter Kahrel
Community Expert
Community Expert
May 6, 2013

Hi Kasyan,

Instead of this:

file = new File(bookContent.fullName);

files.push(file);

you can do this:

files.push(bookContent.fullName);

because bookContent.fullName is already a File.

Peter

Kasyan Servetsky
Legend
May 9, 2013

Thank you for pointing this out, Peter.

Sometimes I overcomplicate things.

Kasyan

Peter Kahrel
Community Expert
Community Expert
May 6, 2013

Documents in a book are objects of type bookContents. Open a document, process it, and save/close it. Do that with all book documents.

Peter