one inch frame
the personal site of eric a. Farris

Better Podcasts into Party Shuffle Applescript

As I’ve written previously, the combination of Applescript + cron automatically adds podcasts to my Party Shuffle throughout the day. Since upgrading to iTunes 7, however, the scripts don’t seem to work as well as they did before. After playing with the scripts for a bit, I’ve got a solution that works better in iTunes 7, and is probably a more bulletproof way to do the job, anyway.

Before, the script was designed to delete the upcoming tracks in Party Shuffle, then add the podcast. iTunes would then fill in the rest of the Shuffle with tracks from the source. In iTunes 7, though, the automatic fill in would happen too fast for that script, leaving the podcast at the end of the Party Shuffle, or sometimes somewhere in the middle. The idea is that the podcast would play next, so this wasn’t an option.

So, here’s what i’ve come up with:

property the_subscription : "NPR: Hourly News Summary"

tell application "iTunes"
        set podcast_playlist to some playlist whose special kind is Podcasts
        set podcasts_to_play to file tracks of podcast_playlist whose played count = 0 and album = the_subscription
        set next_track to the location of last item of podcasts_to_play
        set this_track to add next_track to playlist "Party Shuffle"
        set rest_of_tracks to a reference to (every track of current playlist whose index > 11 and index < 27)
        tell playlist "Party Shuffle" to delete rest_of_tracks
end tell

This is pretty close to the original script, but with a change in logic that, so far, has done the trick every time. This new one adds the podcast to the end of the shuffle, then deletes the tracks in between the currently playing one and the new addition. It does this by relying on the index property of a playlist’s tracks. Since I have my Party Shuffle to show 10 recently played songs, and 15 upcoming songs, we can assume that the currently playing track would have an index of 11, and the last randomly chosen track an index of 26. Therefore, the podcast will have an index of 27, so anything from 12 through 26 can be deleted.

As with the previous script, this one uses a property at the top that is set to the album of the podcast, so it’s easy to modify for other podcasts. The example script above is for the NPR hourly news summary, and it picks the last podcast available for download. This is to ensure that I’m hearing the most recent download, as occasionally the scheduled download will get more than one, depending on the reliability of the feed. For other podcasts, I want to hear the oldest podcast, which just involves changing the line setting the next_track from last item to first item.

Also as with the previous script, you are free to use this however you like, as long as you share the updated script back with me.

-->