Mac OS X

The iTunes Alarm Clock

I know, weak post Charles…  Whatever, I think it’s cool so get over yourself – there’s still a little command line fu so it’s ok (right?)…  Now on to: How to use iTunes as an alarm clock.

I have at times been stuck in hotel rooms and chosen to use iTunes as my alarm clock.  Yes, my phones (why does everyone in IT have more than one smartphone these days) can easily act as alarm clocks.  For that matter, so can my travel alarm clock, the one they put in the room and the wake-up call.  But some of us aren’t morning people and need our fault tolerance.  Also, some of us get violent toward said clocks at times and ergo need a little high availability.  But despite the occasional loss of a document and kernel panic (both of which I’m sure are my fault anyway), I’m never violent towards my laptop (mostly because they have a tendency to retaliate).

First let’s look at how to open a song in iTunes from the command line.  This is pretty straight forward.  First find the file you want.  For most people, it will be in the user home folder under Music and then iTunes, then iTunes Music and then the artists name then the record name and then you should see the song name.  Next  open Terminal from /Applications/Utilities and type open and then hit the space bar.  Now drag the file that you had browsed to in your Finder window onto the terminal window and it will create a line that looks something similar to the following:

open /Users/cedge/Music/iTunes/iTunes Music/Israel Kamakawiwo’ole/Facing Future/14 Somewhere Over the Rainbow _ What a Wonderful World.m4p

open /Users/cedge/Music/iTunes/iTunes Music/Israel Kamakawiwo’ole/Facing Future/14 Somewhere Over the Rainbow _ What a Wonderful World.m4p

Now hit enter, preferably with iTunes closed.  You should notice iTunes open and immediately start playing that song. If not, maybe your default application for the file isn’t iTunes and needs to be changed.  Now that you know a command to play the song, let’s create a file that contains nothing but that command and call it wakeup.sh.  Next we’re going to use the batch command to schedule a job to run in about two minutes into the future (if you type really, really slow then maybe 5 minutes into the future).  The at command can be used to schedule a job.  The job might be to open a file, which would use the -f option followed by the file and then the time.  For example:
at -f wakeup.sh 01:28am
Once the time comes iTunes should fire up and the file should open right up.  We could also have used the batch command or done this a few different ways, but since it’s one job, one time, at is the easiest way to do things.  So let’s go ahead and put in the real time and tell the command to fire off.  Go ahead and crank those speakers so it will wake ya’ up.
Now, if you want a recurring kinda’ thing consider launchd or cron.  This will allow you to schedule jobs to run every weekday, for example.  Or, if you just don’t like using the command line, you should consider checking out iTunes Alarm Clock, from Robbie Hansen, which comes with —-a snooze button—-.  Fun stuff.

PS – Don’t forget to disable Energy Saver if you’re gonna’ use your machine as an alarm clock; if the machine is off it’s not a very useful alarm clock…