Site logo

Night Shift Runner for the Christmas card project

A big batch of the Christmas card project can take many hours: hundreds of schools, thousands of classes, a print file for every product of every class. Nobody wants to sit in front of InDesign all day waiting for it, so this season I added a way to run the whole thing at night. You set it up once, go home, and in the morning the print files are waiting.

There are three parts: the Run unattended option in the main script, a small VBScript called NightShiftRunner.vbs, and a task in the Windows Task Scheduler that starts it.

Why not just start InDesign from the Task Scheduler?

InDesign has no command-line switch that runs a script, so you can’t simply tell the Task Scheduler to start InDesign.exe with a script. Instead, a VBScript attaches to InDesign through COM (or starts it) and calls DoScript on the main script — exactly what you’d do from Visual Basic. An AI agent or any other clever tool isn’t needed: a scheduled task and twenty lines of VBScript are simpler and much more predictable.

Run unattended

The project is split into two scripts on purpose. Settings.jsx only shows the dialog box and saves the settings into the application (with app.insertLabel). Main.jsx never shows a dialog: it reads the saved settings back and works on its own. So you set the options during the day, tick Run unattended, and the night run uses them.

In unattended mode, the main script:

The runner

Here’s the heart of NightShiftRunner.vbs, without the logging details:

Const JAVASCRIPT_LANG = 1246973031    ' idScriptLanguage.javascript

On Error Resume Next
' Attach to a running InDesign, or start one
Set myInDesign = GetObject(, "InDesign.Application")
If Err.Number <> 0 Then
    Err.Clear
    Log "No running InDesign found, starting a new one..."
    Set myInDesign = CreateObject("InDesign.Application")
End If

Log "InDesign version: " & myInDesign.Version
Err.Clear
myInDesign.DoScript scriptPath, JAVASCRIPT_LANG
If Err.Number <> 0 Then
    Log "ERROR during DoScript: " & Err.Description
Else
    Log "Main script finished."
End If

A few things that are easy to miss:

Setting up the task

In the Task Scheduler (taskschd.msc), use Create Task, not Create Basic Task, so you can see all the options:

Also check the computer itself: it must not go to sleep or hibernate at night, and InDesign should be opened by hand once after every update, so that any first-run or sign-in dialog is dismissed before the night run meets it.

When it doesn’t work

InDesign opens and closes again

The most common report: at the set time, InDesign opens, closes after a few seconds, no errors, nothing processed. The closing itself is normal. When the runner starts InDesign through COM, InDesign quits as soon as the runner lets go of it. So InDesign closing quickly means the runner finished quickly, and that usually means the main script stopped at once:

Both logs tell you which: the runner’s vbs_run.log and the main script’s Error Log on the desktop. In the History tab of the task, look at the times of “Task Started” and “Task completed”: if they are in the same second, the runner didn’t even get as far as waiting for the main script.

Test it during the day

You don’t have to wait for 2 a.m. Set the trigger a minute ahead, or right-click the task and choose Run. A daytime test is also a good diagnosis: during the day, the network drives are connected and the other computers are awake, so if it fails then, the problem is in the setup, not in something that happens only at night.

Another test is to run the runner by hand in a Command Prompt:

cscript //nologo "C:\path\to\NightShiftRunner.vbs"

If it works there but not from the Task Scheduler, the problem is in the task’s settings (privileges, session, drives). If it fails there too, you see the error on the screen.

“How do you want to open this file?”

If Windows asks at night which program to use to open a file, some task is starting a .vbs or .jsx file directly instead of through wscript.exe — often an old copy of the task left over from an earlier test. Don’t pick a program: Windows will remember the choice. Close the window, look through the whole Task Scheduler Library list, and disable the task you don’t need.

What it doesn’t solve

The runner starts the job, but if InDesign freezes in the middle of a run, the runner freezes with it: it’s waiting on the DoScript line. I wrote about the causes in When InDesign stops responding, and about the safety net for it in Watchdog.

Pages about this project