Over on the Adobe InDesign Scripting Forum, Bob Levine asked:

I have a client in need of a script to print every nth page in an InDesign book. The book could be more than 20,000 pages so manually entering page ranges isn’t going to work.  Has anyone written anything like?

My answer was the following script.

// BS"D
// Print Every Nth Page From InDesign Book
// An InDesign script Copyright (c) Bookraft LLC, 2016
// Another freebie script from www.Id-Extras.com
// This code is released under the GNU Public License (GPL)
// This script has not been thoroughly tested. Use at your own risk only!

var b = app.activeBook;
var f = b.bookContents;
var d = []; // The book documents
var p = []; // All the pages
var q = app.printerPresets.itemByName("test"); // Type the name of the printer preset here
if (!(q.isValid)){
   alert("The printer preset you have selected cannot be found,");
var s = 1; // The start page (absolute numbering)
var n = 5; // Print every nth page
var i;
for (i = 0; i < f.length; i++){
   p = p.concat(d[i].pages.everyItem().getElements());
   d[i].printPreferences.activePrinterPreset = q;
   d[i].printPreferences.printBlankPages = true;
for (i = s; i < p.length; i += n){
   d = p[i].parent.parent;
   d.printPreferences.pageRange = "+" + (p[i - 1].documentOffset + 1);

To use the script, please note the following:

The script assumes you have an InDesign book open.
In line 12, type the name of the printer preset you want to use.
In line 17, set the start page.
In line 18, set the interval.

The script will first open ALL the documents in the book, simultaneously. I hope that won’t grind ID to a halt in the event of very large books. They could, obviously, be opened and closed as needed, but for the script it’s simpler this way. It also leaves them open at the end.

Then, it sends each page to the printer. In my minimal testing, I noticed that trying to print blank pages causes an error unless specifically allowed (hence line 24). There may be other such things that cause an error.

The only error checking in this script is to see whether the print preset actually exists.