Delete from reference from iTunes

I’m hoping this is simple. My script below takes a .mov file, converts it and then deletes the .mov file from iTunes.

Perhaps this is my faulty understanding, but what happens is that there is still a reference to the deleted .mov file in iTunes. My attempt to specifically remove it doesn’t affect it. Get info on the file in the iTunes browser indicates it’s missing.

Why does the reference not get deleted? thanx, sam


set kipper to 1
with timeout of (900 * 3) seconds
	tell application "iTunes"
		
		set harvey to (add ("Bell:Users:sam:Documents:" & kipper & " Rush.mov") to user playlist "b-ruskie")
		--Change the name of the imported track to be the new name	
		set importedTrackName to ""
		set name of harvey to importedTrackName
		set maude to (convert harvey)
		set newMp3 to (every track of playlist 1 whose name is importedTrackName and kind is "MPEG audio file")
		set fran to location of harvey
		--set island to reference of harvey
		tell playlist 1
			delete harvey --island
		end tell --playlist 1
		tell application "Finder"
			
			delete fran
		end tell --finder
		
	end tell --ituens
end timeout


Sam:

Here is how I do it:

Declare an empty list at the beginning of the script:

set these_files to {}

During the iTunes tell block, use that list to store the location of the tracks you are processing, just before you delete them:

if the location of this_track is not missing value then
set the end of these_files to (the location of this_track) --stores location of track before deleting it from the playlist
end if
delete this_track

After all the processing is finished, use a Finder tell for the final deletion:

tell application "Finder" --Goes to the Finder for final deletion
repeat with i from 1 to the count of these_files
set this_file to (item i of these_files) as alias 
delete this_file
end repeat
end tell

That just places the files in the trash, but you can also do this to empty it out:

tell application "Finder" to empty trash

Hope this helps,