This one is for Randy, who would like to sync his shuffle with a playlist. I went ahead and chose audio-only unplayed podcasts, but feel free to modify as needed. The script includes some oddball uses that work but look ugly. Like the conversion of “none” to string and the use of the floc local variable. Got a better way? See some obviously bad coding here? Let me know in the comments. Thanks go to Mark Hunte for several improvements.
tell application "iTunes"
-- Create playlist if it does not already exist
set podString to "Podcast Playlist"
if not (exists playlist podString) then
make new playlist with properties {name:podString}
else
-- Remove all existing podcasts in playlist
delete every file track of playlist podString
end if
-- Collect every track that has downloaded
set tracklist to every file track of playlist "Podcasts"
-- Add audio-only items that are still unplayed
repeat with eachItem in tracklist
if ((video kind of eachItem) as string is "none") and ((played count of eachItem) is 0) then
set floc to location of eachItem
add floc to playlist podString
end if
end repeat
end tell
Here’s Mark’s take on the script:
tell application "iTunes"
set Shuffle_List to "Pod_Shuffle"
set Pod_list to user playlist "Podcasts"
set pod_tracks to location of (every file track of Pod_list whose size is greater than 0)
if not (exists playlist Shuffle_List) then
make new playlist with properties {name:Shuffle_List}
end if
delete every track of user playlist Shuffle_List
add pod_tracks to user playlist Shuffle_List
set view of browser window 1 to playlist Shuffle_List
end tell


Eh? why not just use a smart playlist for this? I have a number of smart playlists that give me audio podcasts, video podcasts, and pull out the ones that I'm keeping semi-permanently rather than listening in sequence.
For example, my "Audio Podcasts" playlist is:
"match all of" "podcast is true" "playcount is 0" "playlist is not in video podcasts"
and my "video podcasts" playlist is:
"match all of" "podcast is true" "kind does not contain audio" "playcount is zero".
It's simple. No need for applescript.
Nice! However, I couldn't figure out how to do the "playlist is not in video podcasts". Here is my best attempt:
for the smart playlist, just add the rule:
Kind contains audio
and you wont get the video podcasts
I also have the rules:
Genre is Podcast
Play Count is 0
Wow, so much help! It really helps that I use iClip and always keep a copy of Devon Notes active all the time.
I don't mind spaghetti code.....you should see some of my basic and assembly language programs ;-)
I think I will try the smart playlist method first. If it works for me then I won't have to worry about updating the podcast playlist as iTunes will do it for me!
Thanks everyone for all the help!
Sorry. I created the video playlist first, so the audio playlist could reference it.
The suggestions for smart playlists are great, except that what I would like is for only the oldest unplayed episode of each podcast to get copied to my iPod. Because my Shuffle plays podcasts in reverse chronological order, if I don't copy just one episode per podcasts, I will hear them in the wrong order. That doesn't matter for some podcasts, but does for others.
I've been trying to modify this script to do that, but I can't find any way to get the podcast's 'Release Date'. Sorting on the modification date doesn't seem to work reliably.
It may also be that there's some setting I'm overlooking that would change the order the podcasts are played.
I'm still in search of a way to get only 'new' podcasts in a playlist. Most of the podcasts that I listen to never actually get a play count above zero because I skip past final bits. iTunes knows when a podcast is new... it puts a little dot beside it. Grrr... why isn't that attribute exposed for end users to take advantage of :)
Josh and Andrew: After playing around for a couple of days, the best I can offer you is to try approaching this with shell scripts rather than iTunes. Sorry!