Using the ‘scheduleScript’ method

The Scripting Module provides a scheduleScript method that allows you to automatically execute an ExtendScript file at a scheduled time or on a repeating interval. This is useful for tasks that need to run regularly without manual intervention — for example, synchronising a data source every hour, or generating a report at the end of each working day.

Scheduling a script

The scheduleScript method should be called on the EasyCatalog object. It takes two parameters: a cron expression that defines when the script should run, and a File object pointing to the script to be executed:

JavaScript

In the example above, the script cron job.jsx will be executed once every hour.

The cron expression

The first parameter uses the standard cron expression format. A cron expression is a string made up of five fields, separated by spaces, each representing a unit of time:

FieldAllowed values
Minute0 – 59
Hour0 – 23
Day of month1 – 31
Month1 – 12
Day of week0 – 6 (0 = Sunday)

An asterisk (*) means ‘every’, and the /n notation means ‘every n’. So */30 in the minute field means ‘every 30 minutes’, and */1 in the hour field means ‘every hour’.

Some common examples:

ExpressionMeaning
*/30 * * * *Every 30 minutes
0 9 * * *Every day at 9:00 AM
0 18 * * 1-5Weekdays (Mon–Fri) at 6:00 PM
0 0 1 * *First day of every month at midnight

Further information on the cron format can be found on Wikipedia.

Error logging

If a scheduled script encounters an error during execution, the details are written to a log file in the same folder as the script. The log file takes the same name as the script but with a .log extension.

For example, if your script is located at /Scripts/cron job.jsx, any errors will be written to /Scripts/cron job.log. Check this file if a scheduled script does not appear to be running as expected.


NOTE: Use of this function in a desktop environment may violate the end user license agreement for Adobe InDesign, and is provided for testing solutions that will ultimately be transferred to InDesign Server.  Please consult your EULA with Adobe for further information.