-- Insert the newest CNN news update into the party shuffle, if we're listening to it. tell application "System Events" if (name of processes) contains "iTunes" then tell application "iTunes" -- Get the newest CNN news update set podcastPlaylist to playlist "Podcasts" tell podcastPlaylist set cnnUpdates to (every track whose  artist is "CNN" and  date added is greater than ((current date) - 61 * minutes)) -- Only add the very latest update. set cnnUpdate to (a reference to item 1 of cnnUpdates) end tell -- Don't insert this if we're not listening to the Party Shuffle if (player state is playing and  name of current playlist is "Party Shuffle") then my ps_play_next_ref(cnnUpdate) end if end tell end if end tell -- Append Ref to Party Shuffle after current song on ps_play_next_ref(theTrackReference) tell application "iTunes" set thePlaylist to playlist "Party Shuffle" try play thePlaylist set isPlaying to container of current track is thePlaylist if (isPlaying) then set startIndex to index of current track on error set isPlaying to false set startIndex to 0 end try tell thePlaylist set oldTracks to a reference to (every track whose  index > startIndex and  index is less than or equal to (count tracks)) duplicate theTrackReference to thePlaylist duplicate oldTracks delete oldTracks end tell end tell end ps_play_next_ref