Download Available TV Show Subscription Purchases

How to automatically get the latest available episodes from the iTunes Store as soon as you receive the email notification.


The basic scenario

If you subscribe to any TV Shows from the iTunes Store Apple can send an email notifying you when the latest episode is available*. Then you can go to iTunes' "Store" menu, click "Check for Purchases...", and the download will commence.

A while back I had posted a script called Check For Purchases which used GUI scripting to automate this process. It required that you hardcode your iTunes Store user name and password in the script and also have GUI scripting enabled. Yuck. These are two of my least favorite--if not my most least favorite--techniques for using a script. But, it turns out, there's an even simpler and better way to accomplish this.

The script

As of Snow Leopard (OS 10.6), Script has been renamed AppleScript and is located in your /Appplications/Utilities/ folder. This article refers to Script but AppleScript also applies.

Correspondent Ben Schob wanted Mail to trigger Check For Purchases upon receiving the notification from Apple--which is how I recommended it be used. However, in this circumstance, it could run at any time. Couple this drawback with another drawback: the script relies on GUI scripting which requires iTunes to be made the frontmost process in order to work, and this is a problem if you're in the middle of doing something else with another application. Ben wanted Mail and iTunes to do their parts in the background without interrupting what he might be working on at that moment. So he did some investigating. He found that the iTS notification email contains a URL which can trigger the download via a web browser. The URL opens a web page which closes almost immediately and then triggers iTunes to start downloading. So, he downloaded the page to examine the code and found the mechanism used to talk to iTunes. It's just a simple URL which, when called from within iTunes, will look for any available purchases and download them, even while iTunes is (and remains) in the background. Conveniently it also suppresses the "All purchases have been downloaded" dialog that is normally displayed when "Check for Purchases..." is performed manually and no downloads are available.

Here is the script:

tell application "iTunes"
	open location "itmss://"
end tell

Save the script as a "Script" (or "Script Bundle" on older systems), leave the "Options:" checkboxes unchecked, and name it "Get Available Purchases"; you can name it anything you want, really, but that's how I'll be referring to it here on out. I recommend making it available in the system-wide Scripts Menu so it is accessible from any application, in which case you want to save it to your [username]/Library/Scripts/ folder.

If iTunes is not running when you run the script, the launch command will activate it without making it frontmost; if iTunes is already running, launch has no effect, but iTunes will remain in the background if that's where it is. (This is launch's behavior as of Mac OS 10.5.)

Using it with Mail

The beauty of this script is realized when you set a Mail rule to fire it when you receive the iTS email notification. Mail runs in the background, Mail Rule runs in the background, script runs in the background, iTunes runs in the background. Here's how to set that up.

  1. In Mail, go to Preferences... > Rules and click the "Add Rule" button.
  2. In the "Description" box enter a name for the rule. I'm giving it the name of the script, but whatever you like is fine.
  3. Select "all" in the pop-up, such that the setting reads "If all of the following conditions are met:"
  4. Set the first condition to: From Contains

  5. Press the "+" button and set the next condition to: Subject Contains

    New episode available for download

  6. In the "Perform the following actions:" box, set the first action to Delete Message. This is an optional action, but unless you like to keep these emails I'd include it.
  7. Press the "+" button and set the second action to: Run AppleScript and choose the path to the script. If you followed my saving advice above, this path would be ~/Library/Scripts/Get Available Purchases.scptd
  8. Click "OK" and you're done.

Looks like this at my house:


* If you currently subscribe to any TV Seasons at the iTunes Store and don't get the email notifications, what's the matter with you? Log into your iTunes Store account by going to the Store and clicking on your account name in the lighter gray box in the upper right hand corner of iTunes, beneath the Search box. Click the "Manage Passes" button. In the "Current Passes" section, click the "Email Notification" checkbox adjacent to your shows.

Smarties in the audience will no doubt want to remind us that iTunes will automatically Check for Purchases on startup. That's true. But as of this writing, the last time I restarted iTunes was about five days ago.

Many thanks to Ben Schob for the leg-work and the tip!

Site contents © 2001 - 2024 (that's right: 2001) Doug Adams and weblished by Doug Adams. Contact support AT dougscripts DOT com. About.
All rights reserved. Privacy.
AppleScript, iTunes, iPod, iPad, and iPhone are registered trademarks of Apple Inc. This site has no direct affiliation with Apple, Inc.
The one who says "it cannot be done" should not be interrupting the one who is doing it.