Crontab and Applescript

Is there a way to edit my crontab so that it will execute an Applescript? I guess what I am looking for is:
1)Does the script have to compiled or saved as an application?

         2)Do I have to put another command as part of the crontab?

         3) #1 and #2 is assuming that it can be done.

Or is there another utility such as the old Do Script Scheduler for OS9 around now to use?


Since I’m not familiar with cron, I’ll offer these script scheduling utilities. If I’m not mistaken, Script Timer X is developed with AppleScript Studio by a fellow scripter. :slight_smile:

– Rob

If saved as an application, you can call it via cron just like you’d execute any other app (i.e. just reference it by pathname).
Alternatively, ‘osascript’ can compile and execute an applescript, either on the command line or sourced from a file.

The file can be a plain text copy of the script, or can be a compiled AppleScript - as long as the script was compiled in the data fork not the resource fork:

osascript -e ‘beep’ – run the AppleScript code ‘beep’
osascript /path/to/file.scpt – run the compiled script /path/to/file.scpt
osascript /path/to/file.txt – run the plain text script /path/to/file.txt

I use a program called “CronniX.” It puts a GUI on cron. I save my scripts as applications and then have cron (via CronniX) run them at the appropriate time(s).

Hope this helps,
Brad Bumgarner, CTA

I don’t think the original poster’s question was as much about how to setup cron as it was how to run an AppleScript via cron.

Yeah. That’s how I run applescripts via cron.

Thank you so much for the reference to osascript! Since installing Mojave last fall, I’ve been searching for a way to make my Folding@home client scripts automated again using cron. They got broken by Mojave.

This might provide a potential solution: Fixing cron jobs in Mojave

However, it’s worth bearing in mind that cron has officially been deprecated in macOS for quite a few versions, and Apple have recommended using launchd instead. Taken from this link:

And from the crontab manpage:

If you’re interesting in using launchd to schedule your AppleScripts, then here’s a short guide. You can adapt the example from that link to execute an AppleScript by replacing the ProgramArguments key in theirs with this:

(or .scpt). Avoid spaces in the file path. To supply code by way of a command line argument, I think you can do this: