Here’s a wrapper to deal with books. Make sure there’s an open book, then run the script. The script opens, processes, and closes the book documents one by one.
(Hope you don’t feel I’ve hijacked your script, Keith.)
(function () {
function removeBackgrounds (myDoc) {
var myRectangleArray = myDoc.rectangles.everyItem().getElements();
for (var j = myRectangleArray.length-1; j >= 0; j--) {
var myItem = myRectangleArray[j];
if ((myItem.graphics.length > 0 ) || (myItem.images.length > 0)) {
myItem.fillColor = myDoc.swatches.item("None");
}
}
}
var chapters = app.activeBook.bookContents.everyItem().getElements();
for (var i = 0; i < chapters.length; i++){
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
app.open (chapters[i].fullName);
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
removeBackgrounds (app.activeDocument);
app.activeDocument.close (SaveOptions.YES);
}
}());