Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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!!

share|improve this question
1  
Have you tried adding a delay at the start of the script? Or checked if it's run at all by for example adding a say command somewhere? Or playing the sound file with for example afplay or iTunes? –  ؘؘؘ Aug 1 '12 at 14:27
    
FWIW, Calendar (iCal) no longer supports scheduling scripts on Mountain Lion. I've tried doing something like this with launchd, but it got too complicated since I had to use pmset to wake the computer from sleep and a shell script to modify the property list of the agent. You might look into other options like third party applications. –  ؘؘؘ Aug 1 '12 at 14:38
    
@Lri: (1) I'm trying it with a delay command in there now. (2) I'm on Snow Leopard and have no plans to update for the forseeable future. When Mountain Lion becomes necessary I'll just use cron or something. Thanks for the tip, though. –  SoItBegins Aug 2 '12 at 9:34

1 Answer 1

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!

share|improve this answer

Your Answer

 
discard

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.