Open All or Close All in the Book Panel Menu
In the Book panel menu you can double-click any single document to open it, and you can use Ctrl/Cmd+click to select more than one document as well — but this is a bit cumbersome if you want to open all documents. Besides, once you opened all documents of a single book, you might want to close them all again. There is a hidden shortcut to close all documents (it’s Cmd/Ctrl+Shift+Alt+W) — but what if you have other files open as well and you want to keep them open (while closing the book documents)?
Figuring it Out
var book = app.activeBook;
var text = '';
for (var d=0; d<book.bookContents.length; d++)
text += book.bookContents[d].fullName + ' = ' + book.bookContents[d].documentPageRange + '\r';
Opening all of them is easy: just issue the command
for each of the files. Closing the right documents, however, needs a trick, because a document doesn’t ‘know’ to which book it’s associated. The easiest way to make sure the right document closes is to open it using the line above, and then close this new document straight away.
That would make two nice new scripts, but it’s even nicer when you can add them as proper menu commands to the Book Panel menu! I’ve never added menu items before, but fortunately Marc Autret wrote a blog post on this (How to Create Your Own InDesign Menus), and then it only took some fidgeting to replace his example with my code to open and close book documents.
Download the Script
The complete script can be downloaded from my site.
This is not a regular script, as it must always stay in memory and be ready to be called upon, and so you must not copy it into the usual place (your User Scripts folder). Instead, you place it in a special folder called “Startup Scripts”. To get to the correct location in one single step, right-click the folder “User” in the Scripts panel and choose “Reveal in Explorer/Finder”. You will see the regular folder “Scripts Panel” in which everything in the Scripts panel is stored — but don’t put this script in there! Instead, unpack the zip file at this location; it will add the folder “Startup Scripts” automatically.
Then restart InDesign, and open or create a Book file, and look in the book panel menu to check if it works:
Yes it does, and from now on we have our useful new options ready to go!
A note on “activeBook”
One more note, in case you’re going to be scripting book panels: Before you add your own custom options to the Book panel, you have to make sure it works as intended in a standalone script. Now there is something weird going on when using ‘activeBook’. Other than, say, ‘activeDocument’, ‘activeBook’ does not always get right what book document is the active one! The reason for this is that you can have several book panels open at a time, scattered about your workspace. Which one is then “active”? So when experimenting with this, you’d better make sure you only have one single book open.
I was kind of weary of this issue when testing my open/close script, but it seems that if you call a script from within the book panel itself, ‘the’ active book is indeed the one you called the menu from, so the problem resolved itself.