Schedule iTunes AppleScripts with iCal

Note: This tip works with versions of iCal before version 1.5.1. Version 1.5.1 has the ability to schedule AppleScripts already built-in. For information on writing scripts for that feature, read iTunes Scripts for iCal.

 

[jan 21 '03] As you may know, you can set up iCal Events to notify you by email as they are about to occur. Apple recently described a method whereby iCal could be modified to instead run AppleScripts as the "event action". This Apple-hack method involves editing the iCal Package installation, which is not difficult to do, and replacing an AppleScript with another provided by Apple. You can read about it here at Apple's site. Do that, then come back here.

Once you have set up iCal Events to fire AppleScripts, you can create some AppleScripts to control iTunes. Below are some examples you might like to put in your iCal Scripts folder (which you create as described in Apple's instructions).

Let's do an easy one. Just start iTunes, no matter what playlist is selected:

tell application "iTunes"
   play
end tell

Well, we had to start somewhere. Let's say you want to play a playlist called "Morning Wake-Up":

tell application "iTunes"
   play playlist "Morning Wake-Up"
end tell

OK. These are too easy. Let's get complex. Let's create a morning wake-up script that 1) opens and hides iTunes, 2) selects and shuffles a playlist, and 3) sets the volume to something that won't wake your roommate. It's actually pretty easy. We will continue to use the "Morning Wake-Up" playlist, but you can substitute the name of any playlist including "Library". Have a look:

tell application "iTunes"
   launch
   set visible of front window to false
   set view of front window to playlist "Morning Wake-Up"
   copy (get view of front window) to myPlaylist
   set shuffle of myPlaylist to true
   set sound volume to 25 -- 0 = no volume, 100 = full volume
   play myPlaylist
end tell

Save this in Script Editor as a Compiled Script and put it in that iCal Scripts folder you set up. Follow the instructions from Apple and you've got yourself a simple Alarm Clock!

But wait, there's more!

My favorite internet radio station has a cool program on at 3:00PM and I want iTunes to start playing it for me. First, you need to create a new playlist in iTunes and drag the radio track to it. Make sure it's the only track in there and name the playlist whatever you like. For our example, I have copied the radio track to planetZappa to a playlist called "Zappa". Just compile the script below and put it in iCal's Scripts folder and set up an iCal Event as proscribed in Apple's instructions:

tell application "iTunes"
   play playlist "Zappa"
end tell

Hey, same script terminology as before! You're gonna wanna quit your job to stay home and do this stuff all day!

If you need more ideas on stuff to script, have a look around this site, particularly at the Pick 'n' Pull pages.

This column is printer-friendly.
Site contents © 2001 - 2009 Doug Adams and weblished by Doug Adams, dougscripts AT mac DOT com.
All rights reserved. Legal.
AppleScript, iTunes, and iPod are registered trademarks of Apple Inc.
Image 01 Image 01 Image 01 Image 01 Image 01 Image 01 Image 01 Image 01 Image 02 Image 03 Image 03 Image 03 Image 03