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:
- sets
app.scriptPreferences.userInteractionLeveltoNEVER_INTERACT, so no missing-font or missing-link warning can stop it, and restores it at the end in afinallyblock; - never calls
alert(): an error is written to the log, and then the script throws instead of exiting, so thecatcharound the current school or class skips just that item and goes on with the next one; - writes its logs to the desktop (there’s no open document to put a Logs folder next to), and at the end a run summary: one line per school with the number of errors and PDFs.
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:
DoScriptdoesn’t return until the main script has finished. The runner simply waits for hours on that line.- The runner keeps its own log, C:\NightShiftRunner\Logs\vbs_run.log, in a place that’s always writable. It’s the first thing to look at when something goes wrong, because it shows whether InDesign started at all and whether
DoScriptfailed. - The same runner file works on every computer: it looks for the project folder (the one with Christmas cards - Main.jsx) in a few known places and picks the schools folder the same way the main script does. The only things to edit are a couple of constants at the top.
- When the main script is done, the runner starts the Output Checker, so in the morning every school has a short report saying whether it’s ready to print.
Setting up the task
In the Task Scheduler (taskschd.msc), use Create Task, not Create Basic Task, so you can see all the options:
- General: “Run only when user is logged on”. A locked screen is fine, but the user must be logged on: InDesign needs a desktop session. Leave Run with highest privileges unticked (see Mapped drives and elevated tasks for why).
- Triggers: daily at 02:00, Monday to Friday.
- Actions: Start a program — Program/script: wscript.exe, Add arguments: the full path to NightShiftRunner.vbs in quotes, Start in: the folder that contains it.
- Settings: “Stop the task if it runs longer than 6 hours”.
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:
- the runner couldn’t find the main script (a path written for another computer);
- the main script couldn’t find its Templates or schools folder — very often a mapped network drive that the scheduled task can’t see;
- there was nothing to process in the selected folder.
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.
