Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following code in a text file (myfile.applescript):

#! /usr/bin/osascript
tell application "Google Chrome" to quit

I would like Chrome to shut down each night at 9:15PM, so I added the following cron task to crontab:

15 21 * * * ~/Desktop/myfile.applescript

Unfortunately, the script is not triggering. Any thoughts?

NOTE: I am aware I can use iCal to resolve this problem. However, I'd prefer to not clutter my calendar with a daily script-triggering event.

share|improve this question

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

share|improve this answer

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
-rw-rw-r--  1 jason  staff   278B Mar  2 10:18

$ ./
-bash: ./ Permission denied

$ chmod 764

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

$ ./ 
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

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

$ ./
-bash: ./ Permission denied

$ sh
Hello World!
share|improve this answer
I'm sorry about the terrible filename. It was a temporary file so I gave it a stupid filename. But "sh sh sh" all in a row is very absurd. And for the record: I highly suggest using launchd, cron is easier but launchd is more complete. Apps like Lingon that jaberg referenced really do help to make a functional launchctl plist in a hurry. – Jason Salaz Mar 7 '12 at 16:46

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.

share|improve this answer

Try the following in your script.

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

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.