What if none of the alarm clock apps for OSX work just the way we want them? My favorite app until a couple of hours ago was Robbie Hanson’s excellent Alarm Clock 2 app to wake me up. It is simple, intuitive and did exactly what I needed, which was to let me pick a song from my iTunes and set it as my repeating alarm. But then it couldn’t play Soma.fm streams, which iTunes gladly plays.
Luckily OSX comes with excellent built-in tools to make it play the awesome internet radio at 10am.
Here are the steps:
set volume 10 tell application "iTunes" set the sound volume to 0 play user playlist "MY_PLAYLIST" repeat 10 times if sound volume is less than 100 then set sound volume to (sound volume + 10) delay 3 end if end repeat end tell
The AppleScript is very easy to read. We first set the computer’s volume to full, then start iTunes and tell it to set the volume to 0. Then we tell it to play a playlist. Finally, we gradually increase the volume.
Go ahead and press the “Compile” button, and then the “Run” button to test out the script. iTunes should fire up and start playing the desired playlist.
. Now save the script to an appropriate location – I put mine in my home directory (/Users/Cabanaman/) and called it alarm_clock. AppleScript will save it with a .scpt extension, so it might look like alarm_clock.scpt, depending on our display settings.
MM HH dd mm ww osascript /Path/to/alarm clock script.scpt
Here MM stands for Minte, HH, stands for hour, dd for day of month, mm for month and ww for day of week. osascript is a program that lets us run AppleScript files from the command line. And finally we will want to enter the path to our alarm clock script. Start crontab’s editor:
If we have never done this before, then we are most likely in the vi editor. By default, the vi editor does not let us enter text. Press i to enter insert-mode. Now lets start typing in our crontab entry. Here’s what mine looks like:
00 10 * * * osascript /Users/eyce/alarm_clock.scpt
Thats right. I plan to wake up at 10:00am every day! The *’s represent wild-card entries meaning every day / month / day of the week.
Now, when we’re happy with the line, press Escape to get out of insert-mode, and then type in
:wq and press enter. This will save the crontab settings and quit the editor. Lets type in
crontab -l and press Enter and crontab should show us our new settings.
We are done in Terminal and can type in
exit and press Enter to end the Terminal session and finally quit the Terminal.
And that is all! =). The computer should start up, along with the cron/iCal event, and then the AppleScript, which will start iTunes with our favorite playlist at 10am! Or, whatever time you set yours for 😉