03.14.05
Managing Podcasts with AppleScript
In my last entry on the subject of podcasts, I mentioned that I was planning on writing an AppleScript to help me manage the podcasts to which I subscribe. That AppleScript — my first — is now complete.
My problem was that deleting podcasts after listening to them was not just a matter of dragging a few files to the trash. Let’s imagine, for example, that I have five files from one podcaster. Let’s say that I listened to two of them in their entirety while walking around with my iPod yesterday, meaning there are two files with a play count of 1, and of those two I want to save one to listen to again. And maybe I also started listening to another, realized I wasn’t interested in the subject matter of that particular episode, and stopped listening before the playcount was incremented (which occurs when the iPod reaches the very end of the file). Let us further imagine that all five of these podcasts are labeled according to the date on which they were uploaded, which means absolutely nothing to me, the listener. How do I remember which podcasts I wanted to save and which I wanted to delete? Probably by playing them in iTunes in the hope that the first couple of minutes will be enough to jog my memory.
My new AppleScript changes all that. It looks at all the tracks in the “Podcasts” playlist (which is assigned to them by NetNewsWire 2.0 Beta) and deletes
- tracks with a rating of exactly 1 star and
- tracks with a play count greater than 0 unless they also have a rating of exactly 5 stars
I chose to use the ratings this way because the rating is the only tag I can change while listening to a file on my iPod. If I’m listening to a track and decide I don’t want to finish it, I just set the rating to 1 star and it’ll be deleted the next time I synchronize and run this script. If I want to save something even if I’ve already listened to it all the way through, I set its rating to 5 stars. Otherwise, anything with a play count greater than 0 gets deleted.
By “deleted,” by the way, I mean the track is removed from the iTunes library (which also removes it from the Podcasts playlist) and the file is moved to the trash. At the end of the script, a dialog is displayed showing how many tracks were affected.
So the workflow now is this: when I plug in my iPod, it sends the new play counts and ratings to iTunes and receives any new files I’ve downloaded since the last sync. Then I run the script, cleaning out anything marked for deletion according to the rules detailed above. If any changes are made, the script automatically re-synchronizes the iPod. (A previous version of the script didn’t automatically re-synchronize.)
The script, if you’d like to try it yourself, is here. Since it’s written in AppleScript, it will work on Apple computers only — I’ve tested it on my PowerBook running iTunes 4.7.1 under OS X 10.3.8. To use it, unzip the file and drop the script in /Library/iTunes/Scripts/ (if you want it to be available to all users on your computer) or ~/Library/iTunes/Scripts/ (if not). Please note that I make no guarantees about the functionality or safety of this script, and you use it at your own risk.
Incidentally, everything I know about AppleScript I learned from Beginning AppleScript, and everything I know about controlling iTunes via AppleScript I learned from iPod and iTunes Hacks. If you’re interested in learning AppleScript and/or getting more out of iTunes and your iPod, you can help me out while helping yourself by buying a book through one of those links.
Update: I’ve added a couple of lines to the script so that if it does find tracks to delete, it automatically re-syncs the iPod, so you don’t have to do it yourself. If it doesn’t delete any tracks, there’s nothing new to synchronize, so it skips that step.

zeno Said:
March 15, 2005 at 1:02 am
This is f*c*ing great, thanks!
Now…if only the Shuffle had a rating system :-)
Actually, I think I’ll go buy a 4G iPod only because of this post…being able to put stars in order to manage my podcasts seems too useful to miss! So, yeah, you’re definitely responsible for adding a -$350 entry to my credit card account, LOL!
Christopher Said:
March 15, 2005 at 7:28 am
This is brilliant!
I can’t wait to try it out when I get home from work. And I might even buy those books as well.
Ryan C. Said:
March 15, 2005 at 9:01 pm
Further proof that Apple will take over the world. You’ve helped to make my day. That recent iPod software update did it for the month. :-)
John B. Said:
May 11, 2005 at 7:57 pm
This is a great idea. I wish I had a mac now. This has been one of my bigest problems, trying to delete old podcasts. I had a Mac 10 years ago and Apple Script was too cool. Do you know of anything like this for us Win PC folk, I need something to get me over untill I make the switch back :)
Nicholas Said:
May 11, 2005 at 9:40 pm
Unfortunately, no, I don’t know of any way to do this on a Windows system. I must admit, though, I haven’t spent much time looking for one.
gwbuhl Said:
June 15, 2005 at 5:36 am
This is exactly what I’ve been looking for. I was goign to sit down an write one myself this morning, but this saves me the work. I changed the script a little to just delete all the tracks from a particular play list. I have and “Old Casts” smart playlist for unrated tracks older than month with Podcast of Radio as the genre. I cal runs the delete script to remove files from this playlist on the first of the month.
Thanks.
mike Said:
June 19, 2005 at 3:24 am
great idea!
SonicChicken weblog » Blog Archive » Podcasts and the I-pod Shuffle Said:
June 28, 2005 at 2:07 pm
[...] chives, you can see that I just recently started blogging (and reading blogs). So I missed this post on Acetylene.net. Zeno’s comment mentions listen [...]