Monthly Archives: March 2006

Simple Clock

OK, so I have trouble getting up in the morning. I’m constantly late and unfocused; well, that’s what I’m told. Anyway, I wrote a clock for myself in AppleScript with some borrowed code and some of my own and here it is. The magic of the script takes place in a crontab. The crontab is really simple to make, but it means a trip to the Terminal. I know, I know, I’m supposed to use launchd, and I will get around to that, but the crontab is faster for me. Here’s the script:

tell application "Finder"
set volume 10
end tell
set volInt to 60
tell application "iTunes"
set sound volume to volInt
set song repeat of user playlist "wfae" to one
play track 1 of user playlist "wfae"
end tell
set whichButton to ""
repeat until whichButton = "No, I'm up!"
display dialog "Snooze?" buttons {"No, I'm up!",
"SNOOZE"} default button "SNOOZE"
set whichButton to (button returned of result)
set sleep to "sleep"
if whichButton = "SNOOZE" then
tell application "iTunes"
pause
end tell
do shell script "/bin/tcsh -c '/bin/sleep 300'"
tell application "iTunes"
if volInt < 100 then
set volInt to volInt + 10
set sound volume to volInt
end if
play
end tell
end if
end repeat
tell application "iTunes"
set song repeat of user playlist "wfae" to all
set volInt to 60
set sound volume to volInt
play track 2 of user playlist "wfae"
end tell

Save this as an Application and put it somewhere. Mine's in my home directory.
Open the Terminal and type:

crontab -e

Type the following (crontab -e spits you into vim)

15    8    *    *    *    open    iTunesWakeUp.app

The spaces inbetween the items are tabs. One mustn't forget the tabs, oh best beloved.

type :qw

and you'll get a nice message from the Terminal:

crontab: installing new crontab

You can check it by typing crontab -l

Now, go to sleep and wake up to iTunes.

A few gotchas:
I've pointed my alarm at track one of the playlist "wfae". This can be whichever of your playlists you choose. BTW, track one on my alarm is the sound of an alarm bell.
Track two is the live stream from WFAE, the NPR news station in Charlotte, NC.