geekiest alarm clock ever.

October 31st, 2005

Wouldn’t it be nice to wake up to something other than morning drive-time radio and/or the incredibly annoying BEEP BEEP BEEP of your $12 alarm clock? Wouldn’t it be nice to wake up to a different thing for each day of the week, and on weekends, maybe not be woken up at all? Your Mac can do all this for you, it just needs a little massaging to do so. Here’s how to set this up in a couple of easy steps, and you’ll learn some UNIX scripting and AppleScripting in the process.

  1. First, set up iTunes to have a folder called “Alarm Clock” and seven playlists inside, each named after a day of the week. It’s actually only for the sake of tidiness that the playlists are in a folder, and you can actually name the folder anything you like; the important thing here is to have a playlist for each day of the week you wish to be awakened.

    Fill up the playlists with whatever you want to be awakened to; mp3s, streaming audio, whatever. Anything you place in the playlist for that day will be played. I suggest something light, but it’s your call, man.

  2. Start up “Script Editor” in the Applescript folder of your Applications folder and paste this in:

    set day_of_week to do shell script "date +%A" as string

    tell application "iTunes"



    play playlist day_of_week

    on error

    --do nothing

    end try

    end tell

    What this does is get the day of the week via the UNIX “date” command, and set to a variable called “day_of_week”. Then it tells iTunes to play a playlist with that name. Save this script as an Application (and make sure “Run Only”, “Startup Screen”, and “Stay Open” options are all unchecked). Save it as “Alarm-Clock” and save it to your /Library/Scripts folder.

  3. Now we’re going to set up the scheduling. While you could use iCal to trigger the script every morning, that would clutter up your calendar, so we’re going to use cron scripting. Download a program called “Cronnix“. Cron scripting is an industrial-strength system used on UNIX servers to automate processes that have to happen on a set schedule. Cron scripts, however, are notoriously difficult to write, so we’re going to use Cronnix — a program that allows you to visually modify the user crontab — to help us out, and specifically, we’re going to use it to activate the AppleScript you just wrote.
  4. Open up Cronnix. Click “New”. Click the “Simple” tab. Drag the sliders next to “Minute” and “Hour” to specify the time you want to wake up. Click off the boxes next to “Day” and “Month” because you’ll want the alarm script to run every day, even if you don’t want to be waken up every day. In the “command” box, paste:

    /usr/bin/open /Library/Scripts/

    Click “Save”.

    At this point, you’re all set; your computer will activate the script at the time you specified, it will look for a playlist named after the day of the week and play it. If it doesn’t find the playlist, or if there’s nothing in the playlist, it won’t do anything; so if you don’t have tracks in the “Saturday” or “Sunday” playlists — or if you don’t even have “Saturday” or “Sunday” playlists — you won’t hear anything at all. There are some caveats here; your computer has to be turned on, you have to be within earshot of it, and since the mechanism that triggers the alarm is in your “crontab”, you have to be logged in for this to work… so if that’s not the case for you and your mac, then this isn’t the solution for you.

  5. BONUS POINTS: Get an Airport Express and pipe iTunes’ output through your stereo. Wow, won’t your neighbors be annoyed impressed!


6 Responses to “geekiest alarm clock ever.”

  1. Joshua says:

    Pretty cool, Jeff.

    There’s an additional caveat: if you’re using your stereo, you have to leave it on and set to the AirPort overnight. If you’re watching TV before you go to bed, it’ll sink your big plans.

    I’d say that the thing to do is to use a boom box near your bed, connected to AirPort Express.

    Now, to actually wake you up, it might be best to have something like Clocky. But connected to your MP3 library… this could get to be the first useful house robot.

    And no, I don’t consider Roomba to be a useful house robot unless you have serious problems with landmines in your house.

  2. Randy Bond says:

    I have a bedroom Mac, an old B&W G3, hidden behind the dresser in the corner running iAlarm ( with inexpensive multimedia speakers. It’s connected to my home network, which gives it access to the internet and the iTunes library on my server in the closet. It says “Good morning Randy,” reads me the weather and then plays randomly from my morning playlist. I need more than “something light” to roust me out of bed, so I greet the morning with songs such as the Fenderman’s “Muleskinner’s Blues” or John McDermott’s “Scotland The Brave.”

    iAlarm puts me to sleep playing my evening playlist with songs like Keola Beamer’s “`Imi Au Io `Oe” or Sarah Brightman’s “Dans La Nuit,” During the rest of the day, it crunches numbers for Stanford University’s Folding@Home project.

    iAlarm is simple to use, flexible and reliable. If you want, it can also read you your iCal events or To Do’s, read you the headline news or run applescripts. It will even wake your Mac from sleep to do its duty. It’s worth every penny of the shareware fee I paid.

  3. Jeff says:

    HOLY GOD. Thanks for the link, Randy; and OK, so, let’s retitle this article “second geekiest alarm clock ever”.

  4. Brett says:

    You don’t have to invoke shell commands to get the weekday in AppleScript. This also works:

    set day_of_week to (weekday of (current date)) as string

  5. RobPez says:

    I know iAlarm well, but I don’t have room for a Mac in my closet so i just hooked up powered speakers to an AirPort Express. Also a Bluetooth phone with Salling Clicker comes in REALLY handy!

    I guess you could also drag and drop in Automator to make yourself a quick and dirty solution too.

  6. Jeff says:

    set dayofweek to (weekday of (current date)) as string

    Hey, that’s good to know. Thanks, Brett.