problems with an iTunes script!

hi!

I’ve got a problem with an iTunes-Script! I wrote a littel application to delete die files in the library wich can’t be found:


tell application "iTunes"
		repeat with myTrack in selection
-- my first problem is, that I don't konw how I can tell the script to get the location of the whole library! sth. like repeat with a in the library....?
			try
-- my second problem is, that iTunes can't get every location of the files. That means an error dialog like this appears: "The location of the track id.... can't be found" so I have to use a try command.
				set myLocation to get location of myTrack
				
				if myLocation is missing value then
					delete myTrack
				end if
			end try
		end repeat
end tell

to my first problem:
do you know how I can “talk” with every track of the whole library?

to my second problem:
in one run, iTunes can’t get the location or a missing value of a track. so the script stops.

I used a try command. but this command means, that there are files in the list which can’t be found. If I run the script again and again…, iTunes sometimes get the location! I used a “repeat 10 times-command”, but this command is no guarantee, that all files have been deleted, and it takes very much time!

do you have any ideas?

thank you! nicki

nicki,

take a look at the codes below.

the codes, as they are, may not work as some required codes may be missing, but you should be able to get an idea how to solve your problem.

good luck. :smiley:

archseed


--routine below looks for disabled tracks (a selection marker) to delete from the music library and hard disk;
--then, it looks for dead tracks (files missing but still listed in the library) and deletes them as well

tell application "iTunes"
	set these_tracks to tracks of the playlist "Library"

	set delete_theseTracks to {}
	
	repeat with i from 1 to the count of these_tracks
		set this_track to item i of these_tracks
		set trackEnabled to get enabled of this_track
		if the location of this_track is not missing value and trackEnabled is false then
			set the end of delete_theseTracks to (the location of this_track)
			delete this_track
		else
			set i to i + 1
		end if
	end repeat
	
	
		set i to 0
		repeat with i from 1 to the count of delete_theseTracks
			set this_file to (item i of delete_theseTracks) as alias
			delete this_file
		end repeat

	set frontmost of application "iTunes" to true
	display dialog return & "The script will now remove the "deadlinks" from your library playlist." buttons "OK" default button 1 giving up after 2 with icon 1
	
	tell application "iTunes"
		set thePlaylists to the library playlists
		if thePlaylists = {} then return
		repeat with thePlaylist in thePlaylists
			set selected_fileTracks to file tracks of thePlaylist
			if selected_fileTracks = {} then return
			repeat with selected_fileTrack in selected_fileTracks
				set theLocation to the location of selected_fileTrack
				set theLocation to theLocation as string
				if theLocation = "missing value" then delete selected_fileTrack
			end repeat
		end repeat
		delete this_playlist
	end tell
	beep
	display dialog return & "Your music library has just been cleared of disabled tracks and their resulting deadlinks." buttons "OK" default button 1 with icon 1 giving up after 3
	
end tell

thank you archseed!

I will test your code!

tank you very much!

nicki :smiley:

nicki,

sorry, you don’t need the “delete this_playlist” code. there is no such playlist in the routine that i posted for you earlier.

hope you got the idea and it’s working for you now.

archseed