Applescript won’t play movie when waking from sleep

applescriptaudioicalquicktimesleep-wake

I have the following AppleScript, which is triggered by iCal to act as my alarm clock:

set musicPath to the path to me as text
set musicPath to text items 1 thru -12 of musicPath as text
set musicPath to musicPath & "drumsolo.aif"

set volume output volume 90

tell application "QuickTime Player"
    run
    open musicPath
    tell document 1 --
    play --
    end tell --
end tell

I've also used 'play front document' and 'play document 1' for the block marked with dashes.
The problem is, System Preferences wakes up the computer on time (from sleep, 5 minutes before the script is triggered). The script works, opening the file and turning up the computer's volume.

But, when actually running the script for real, and ONLY then, the darn sound file won't play. It just sits there.
When I tested it w/ Applescript editor, it opens and plays fine.
When I tested it w/ iCal (resetting the event to a new time), it opens and plays fine.
When I reset the computer's sleep time and the day's event, it opens and plays fine.

It's only when I actually put my computer to sleep, rest for 8 hours, and the script wakes the computer that it doesn't play. Help!!

Best Answer

OK, I finally figured it out after writing 4 or 5 different iterations of the code. Adding a delay statement before 'tell document 1' worked— the script was running too quickly and trying to play the final before it was open.

Thanks, Lri!