So, for reasons unclear to me, I have fallen into the habit of listening to the radio on my computer during the day as I work, playing streams via iTunes. I can play feeds from many stations all over the world, but mostly I stick close to home and listen to KUOW, the local NPR gabfest. I actually would prefer if it were a music station but I find myself more irritated than pleased when I listen to the local stations that occasionally play music to my tastes – either they are commercial, and the ads drive me nuts, or they are not, and the taste of the deejays doesn’t often reflect my own.

Lately my local station began airing an NPR-Slate coproduction at midday, Day to Day. I gave the show a try, but it just grates on me. It seems to be a considered attempt from NPR to broaden their base by incorporating contemporary journalistic perspectives that reflect a more conservative bent than often heard on NPR. It’s a project that fits well with the editorial objectives of Slate.

I’m reasonably sure the show’s doomed; I kinda doubt that droves of conservative radio listeners are tuning in to escape the mind-numbing palaver of Dr. Laura and Rush. Day to Day maintains the even-tempered, thoughtful, voice-of-quiet-reason presentation that’s the NPR house style, and as I understand it, that’s the specific element that puts non-NPR listeners to sleep.

So, as you may have noticed, I rarely write about negative news and entertainment consumption experiences. It’s not that I don’t have them, but it is that I don’t think my negative reaction to a given work, show, book, or what not is really, on balance, a positive contribution to discourse in the world.

However, in this case, I was sufficiently motivated to do something about it. Being me, I wrote an Applescript radio-station switcher for iTunes which allows me to set up a schedule with cron, so that during the day, iTunes will switch from station to station according to a schedule – so now, when Day to Day comes on, I find my self listening to WFHB, the non-NPR public radio station that morphed into broadcast existence from several strands of community radio organizations in my hometown shortly after I left.

I use Cronnix to set up the schedule. Cronnix is a GUI front end to cron. I believe that cron is included with the stock OSX install.

You’ll need to make sure you have ScriptEditor – get it from Apple’s Applescript site. I think you must register with the Apple Developer Connection to get the free download, but don’t recall.

Here is a link to a text-only version of the switcher script. Download it, open it in ScriptEditor, change the default values at the top of the script, and Save As > Application to a folder in your Home Library folder, specifically to ~/Library/iTunes/Scripts. The folder will also appear in the menubar for iTunes so you can run the script from within iTunes. When I save the scripts, I name it with the callsign of the station – so the sample script would be renamed as KUOW.

Here’s the part of the script you need to edit:

set myPlaylist to “a radio selection”
set theCallSign to “KUOW”

You need to change “a radio selection” to the name of a playlist which contains the streaming tracks you want to access – you could try it with the default “Radio” playlist, but I have not. Instead, I have a separate, much shorter list.

A note: the script looks for the callsign you enter in the name of the track – but not all radio stations keep that callsign, and when you access the stream, the name of the track may change. Finally, streaming tracks that have certain special characters or a long name may not be called accurately. It wasn’t a problem for me, but might be for you.

If you want to poke around to make this script better, Doug’s Applescripts for iTunes and the associated discussion board will be very helpful. Doug’s Applescripts for iTunes also offers a method to use iCal to accomplish some very similar stuff. I avoid the .Mac apps, though, after the email address bait-and-switch.

So what does the script do?

When it’s run, a voice will say “Switching to KUOW” or to whatever the callsign is you enter. Then it looks to see if there are mounted ejectable discs – that could be CD’s, DVD’s, Jaz, Zip, mounted disk images, whatever.

Then it looks for disc-related apps – Toast and iDVD, but you can add more if you want. Carbon Copy Cloner leaps to mind, actually.

If it sees you do have a disk mounted or one of these apps is active, it asks you if you want to continue. That’s to allow the user a chance to stop the script if you’re doing something that might make the radio streaming unwanted – installing something, backing up, ripping, watching a movie… stuff like that. It’s not the best way to ascertain, but it’s simple and you can always allow the script to continue.

Once that’s out of the way, the script will look in the specified playlist for the first track that contains the callsign you specified. I don’t think I have an explicit error handler in case of no match, but if there’s a problem – maybe iTunes is busy with a modal dialog or in a crucial burning phase – the script will speak, saying, “iTunes is busy at the moment.”

That’s it! I open the script, edit the call signs, and save each time as an Application, naming each applet with the callsign. Then you set up you schedule in Cronnix, and you’re in business.

One thought on “Using Cron to schedule iTunes

  1. I wholeheartedly agree with your assessment of Day to Day (which, I must admit, I believed was Day Today until seeing your link just now.)

    I came to the realization that I had no interest in the show several weeks ago, after listening to a 15-minute piece on Friendster, during which they interviewed someone from Boingboing. The show is little more than a radio-borne weblog and, what’s worse, it’s not even a good weblog.

    Anyone can scrape Boingboing or MetaFilter or Blogdex or Fark and dump the resulting content into a slop bucket. It doesn’t make for a compelling weblog, and it certainly doesn’t make for compelling radio.

    I fully expect them, within next month, to begin re-enacting AIM conversations they had earlier in the week. Until then, I’ll return to my fantasies of setting Ira Glass on fire…

Comments are now closed.