Hi! I’m new to Applescript and have managed to write something to load my iPod Shuffle with music/podcasts (heavily borrowed from here), but I would ideally like to use set the order of tracks on the shuffle once they’ve been transferred. Currently my code deletes tracks/podcasts which have been listened to and then transfers new music/podcasts, but this results in the new music/podcasts being at placed at the end of the stuff already on the shuffle, which makes it impossible to find my new podcasts which I like to listen to first every day. Instead I’d like the podcasts to go to the top of the shuffle track order. The only ways I can figure out how to do this is to either make the code delete everything from the shuffle and then reload in the order I want it - but this seems a bit inefficient, or manually drag and drop the podcasts to the top once transferred, which defies the reason for using the applescript to automate things!
Hope that makes sense! Thanks in advance for any tips…
Kate
PS here is my script
tell application "iTunes"
repeat with thisSource in sources
if the name of thisSource = "kate" then set myIpod to thisSource
end repeat
updateAllPodcasts
-- delete all the podcasts on the ipod shuffle which have been listened to
set destinationPlaylist to the first playlist in myIpod
set sel to every track in destinationPlaylist whose podcast is true and played count is greater than 0
repeat with atrack in sel
delete atrack
end repeat
-- "Shuffle -> podcasts" is a smart playlist that contains new podcasts to be added
set sourcePlaylist to playlist "Shuffle -> podcasts"
-- if statement to only do this if there are new podcasts to add
if the number of tracks in sourcePlaylist is greater than 0 then
set shufflable of (every track of sourcePlaylist) to true
-- if statement to only do this if there are already tracks on the ipod shuffle
if the number of tracks in destinationPlaylist is greater than 0 then
set shufflefilenames to (name of file tracks in destinationPlaylist whose podcast is true)
set newsel to (every track in sourcePlaylist)
-- check each track on the shuffle and see if it has the same name as a podcast about to be uploaded. If it does, change a boolean variable called "donotdup" to true so this track WON'T be deleted
repeat with atrack in newsel
if name of atrack is in shufflefilenames then
set donotdup to true
else
set donotdup to false
end if
if donotdup is false then
duplicate atrack to destinationPlaylist
end if
end repeat
else
duplicate every track in sourcePlaylist to destinationPlaylist
end if
end if
display dialog "all podcasts have been updated and old ones have been deleted"
-- delete all the tracks on the ipod shuffle which have been listened to in the last 7 days (smart playlist selects songs not listened to in the last 2 weeks so these must have been listened to recently on the shuffle)
set destinationPlaylist to the first playlist in myIpod
set sel to every track in destinationPlaylist whose podcast is false and played date is greater than ((get current date) - 7 * days)
repeat with atrack in sel
delete atrack
end repeat
-- "Shuffle -> music" is a smart playlist that contains new music to be added
set sourcePlaylist to playlist "Shuffle -> music"
-- if statement to only do this if there are new tracks to add
if the number of tracks in sourcePlaylist is greater than 0 then
set shufflable of (every track of sourcePlaylist) to true
-- if statement to only do this if there are already tracks on the ipod shuffle
if the number of tracks in destinationPlaylist is greater than 0 then
set shufflefilenames to (name of file tracks in destinationPlaylist)
set newsel to (every track in sourcePlaylist)
-- check each track on the shuffle and see if it has the same name as a podcast about to be uploaded. If it does, change a boolean variable called "donotdup" to true so this track WON'T be deleted
repeat with atrack in newsel
if name of atrack is in shufflefilenames then
set donotdup to true
else
set donotdup to false
end if
if donotdup is false then
duplicate atrack to destinationPlaylist
end if
end repeat
else
duplicate every track in sourcePlaylist to destinationPlaylist
end if
end if
end tell