Day 2 of Cocoa Programming class at Big Nerd Ranch. There's a lot of stuff to learn in there! It's too much to grok at the lightspeed pace of the course, so I'm sort of letting it wash over me and picking up as much as I can. My head is buzzing with ideas for writing and programming projects.
The alarm clock in my room here at the Ranch is too obnoxious to be allowed to live. So being a Big Nerd this week, I decided to solve the problem with technological overkill. My first idea was to write a Cocoa program that included a movie controller to play an MP3, but I soon moved on to the idea of an AppleScript. With the help of fellow nerd student Dave Mark, I wrote a little script to check the time, then play a song at the appointed hour:
set alarmTime to "01/14/04 7:30 AM"
set theResult to display dialog "What time?" default answer alarmTime
set alarmTime to text returned of theResult
repeat until the (current date) > date alarmTime
end repeat
tell application "iTunes"
play track "Amsterdam" of playlist "Library"
end tell
Then I realized I had left the power adaptor in the classroom, and my battery would not last all night. So I changed course a little. I used the Energy Saver preference panel to set the Mac to start up at 7:30 AM. Then I modified the script to simply play the tune and saved the script as an application. I created a new user, Wakey Wakey, set the Mac to login to this user automatically at startup, with the script as its only startup item. I shut down the PowerBook. At 7:30 this morning, it turned itself on, started up into Wakey Wakey, ran the script, and played the song.
Of course, I woke up all by myself about 10 minutes before the alarm fired. But I still had to sit around and wait for it all to happen.