UPDATED: Update Expired Podcasts v2.2 (and launchd project)
iTunes will stop updating a Podcast subscription if you haven’t played at least one of its episodes in five days. Update Expired Podcasts v2.2 will go through every Podcast subscription and update it so you don’t have to manually update each one individually.
This latest version adds a routine that checks to see if iTunes is running before proceeding with updating the Podcasts. Now, you may be asking yourself: if I’m running the script from the iTunes Script menu then why would the script need to check if iTunes is already running? Because: I’m going to show you how to regularly launch the script automatically and invisibly in the background and you may not want iTunes to run when the script fires. If you’re not familiar with launchd then read on.
launchd is a system service that is built-in to the Mac OS. It is primarily used to run programs at startup. But it can also be configured to run jobs at various other times using launch agents (it replaces the deprecated cron which you may have heard of).
I’m not going to explain much about launchd—you can read more about it at Wikipedia or its man page. I’m just going to show you how to create and install the agent that runs a job to fire the Update Expired Podcasts script at startup and every eight hours thereafter. (You will need to restart or logout/login after creating the agent, so be prepared to do that.)
1) First, install the Update Expired Podcasts script in your [username]/Library/iTunes/Scripts/ folder. (By default, the user Library folder is invisible in Lion. Option-click the Finder’s “Go” menu and choose “Library” from the drop down menu.
2) Launch your favorite text editor. TextEdit will do if you don’t have BBEdit, TextWrangler or something comparable. Copy the following into a new document (after some slight modifications this will be saved as the launchd agent):
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Disabled</key> <false/> <key>Label</key> <string>com.YOURUSERNAME.UpdatePodcastsAgent</string> <key>Program</key> <string>/usr/bin/osascript</string> <key>ProgramArguments</key> <array> <string>osascript</string> <string>/Users/YOURUSERNAME/Library/iTunes/Scripts/Update Expired Podcasts.scptd</string> </array> <key>RunAtLoad</key> <true/> <key>StartInterval</key> <integer>28800</integer> </dict> </plist>
If using TextEdit, click the “Format” menu and make sure that the document is plain text and not rich text.
3) Change the two occurences of “YOURUSERNAME” to, uhm, your user name. This is the same as the name of your Home folder.
4) Save the document as “com.YOURUSERNAME.UpdatePodcastsAgent.plist” (change that YOURUSERNAME again) in your [startupdisk]/Library/LaunchAgents/ folder. Note: this is the root-level public Library folder on the startup drive and not the user Library folder in your Home folder or the /System/Library/ folder! If there is no LaunchAgents folder there then create one and save the file in it. You will probably need to authenticate in order to save the file to this location.
5) Restart your computer, or logout and then login again so that your system registers the agent.
Yer done. Now, whenever you start your computer the Update Expired Podcasts script will run. It will also run every eight hours (every 28800 seconds) thereafter, thus making sure that your Podcasts are always updated.
Note that the script will check if iTunes is running and will quit if it isn’t. This is to prevent iTunes from launching when you least expect it. However, if you actually want iTunes to launch when the script is fired by launchd you can edit a single line in the script. Here’s how:
Navigate to the script in your [username]/Library/iTunes/Scripts/ folder and double-click its icon. This will open the script in AppleScript Editor. Locate this line:
if not checkItunesIsActive() then return
Either delete this line or comment it out by placing a “#” at the front of it. Then “Save” the script and Quit AppleScript Editor.