I'm working on an itunes applescript to delete all podcasts on my ipod shuffle that have been listened to, and then add new ones from a smart playlist. The one part of the script that I need help with is some type of if statement to avoid copying a file from the smart playlist if it is already exists on the shuffle. I'm trying to do this by comparing the names of the tracks, but it doesn't seem to work. I'm new to applescript and I have a feeling I'm not using the right type of variables or I'm not building the statement correctly. Can anyone help me out with this? Thanks!!
The statement I'm trying to use is:
if (name of atrack is equal to value of anitem) then
Here is the code:
tell application "iTunes"
repeat with thisSource in sources
if the name of thisSource = "Paul" then set myIpod to thisSource
end repeat
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
set sourcePlaylist to playlist "newpodcasts"
if the number of tracks in sourcePlaylist is greater than 0 then
set shufflable of (every track of sourcePlaylist) to true
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)
repeat with atrack in newsel
repeat with anitem in shufflefilenames
if (name of atrack is equal to value of anitem) then
set donotdup to true
exit repeat
else
set donotdup to false
end if
end repeat
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"
end tell
The statement I'm trying to use is:
if (name of atrack is equal to value of anitem) then
Here is the code:
tell application "iTunes"
repeat with thisSource in sources
if the name of thisSource = "Paul" then set myIpod to thisSource
end repeat
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
set sourcePlaylist to playlist "newpodcasts"
if the number of tracks in sourcePlaylist is greater than 0 then
set shufflable of (every track of sourcePlaylist) to true
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)
repeat with atrack in newsel
repeat with anitem in shufflefilenames
if (name of atrack is equal to value of anitem) then
set donotdup to true
exit repeat
else
set donotdup to false
end if
end repeat
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"
end tell