AppleScript Primer for Mac OS X
Subject:   Alarm Clock with iTunes & Cron Solution
Date:   2003-01-01 21:19:47
From:   anonymous2
I also tried to use cron to call an AppleScript via osascript to open a playlist in iTunes. The mac-as-alarm-clock seemed like a no brainer thing to do. But while the script worked from the command line, cron wouldn't execute it as expected.

Still not sure why, but osascript appears to have limitations requiring that it be called explicitly from the command line in order for it to work right...

The solution was to save the AppleScript in Script Editor as an Application, using the "Never Show Startup Screen" option. Then in the crontab file, just specify the full path to the executable AppleScript Application, avoiding using osascript altogether.

My AppleScript (saved to an Application called 'alarm2') looks like:

tell application "Finder"
set volume 2
end tell

tell application "iTunes"
set the sound volume to 100
play playlist "wakeup"
end tell

my crontab entry looks like:
30 6 * * 1-5 root /Users/bbahner/alarm2

This works great and wakes me up to my favorite music rather than a bone-jarring alarm clock.

Hope this helps.