cron is failing to run my AppleScript

Cron has be deprecated on modern versions of OS X. Apple's suggestion is to use launchd instead. You will find Lingon to be a useful tool for creating launchd daemons.

If you would prefer to use iCal to launch the script, you can create a separate calendar for scripted event(s), and hide it from view. It will function, but your calendar view will not be cluttered.

enter image description here


Make sure the ~/Desktop/myfile.applescript file is executable. You can only call a script by filename if it has the relevant execute bit.

Consider the following Terminal session:

$ ls -laFh sh.sh
-rw-rw-r--  1 jason  staff   278B Mar  2 10:18 sh.sh

$ ./sh.sh
-bash: ./sh.sh: Permission denied

$ chmod 764 sh.sh

$ ls -laFh sh.sh
-rwxrw-r--  1 jason  staff    32B Mar  7 09:40 sh.sh*

$ ./sh.sh 
Hello World!

Until I had execute permissions (denoted with an 'x' in either the 4th, 7th, or 10th slot of the permissions string), I could not run it.

You can override it by calling the file with it's particular interpreter:

$ chmod 664 sh.sh

$ ls -laFh sh.sh
-rw-rw-r--  1 jason  staff    32B Mar  7 09:40 sh.sh

$ ./sh.sh
-bash: ./sh.sh: Permission denied

$ sh sh.sh
Hello World!

I discovered my original script worked. The problem had to do with my cron entry: it wasn't terminated with a carriage return. Once I did that, the applescript triggered properly.


Try the following in your script.

#!/usr/bin/bash
/usr/bin/osascript -e 'tell application "Google Chrome" to quit'

Make sure it's chmod +x and test from CLI.