romaklimenko
3/2/2011 - 7:01 PM

Remove one star tracks from iTunes. Tracks that I want to delete I mark with a single star. It usefull on iPhone and iPod where you can't re

Remove one star tracks from iTunes. Tracks that I want to delete I mark with a single star. It usefull on iPhone and iPod where you can't remove songs without iTunes. Pay attention on hardcoded disk name. You probably should fix it.

tell application "iTunes"
	set mainLibrary to library playlist 1
	set totalTracks to count of file tracks of mainLibrary
	
	repeat with t from totalTracks to 1 by -1
		set this_track to file track t of mainLibrary
		
		if this_track's rating is 20 then
			set the _location to this_track's location as string
			
			set the _disk to "Macintosh HD"
			
			set AppleScript's text item delimiters to the ":"
			set the item_list to every text item of _location
			set AppleScript's text item delimiters to the "/"
			set this_text to the item_list as string
			set AppleScript's text item delimiters to ""
			
			set AppleScript's text item delimiters to the _disk
			set the item_list to every text item of this_text
			set AppleScript's text item delimiters to the ""
			set this_text to the item_list as string
			
			set _script to this_text
			
			delete this_track
			
			tell application "System Events"
				delete file _script
			end tell
		end if
		
	end repeat
end tell