Add to library (and download) button for iTunes

Aha, I fixed it! I was able to stop iTunes from relaunching by wrapping the entire inner contents of the script in a try statement.

if application "iTunes" is running then
	tell application "iTunes"
		try
			set trackName to name of current track
			set libraryCheck to tracks in playlist "Music" whose name is trackName
			set playlistClass to class of current playlist
			try
				set trackClass to class of item 1 of libraryCheck
			end try
			
			if libraryCheck is {} or trackClass is URL track then
				return "add to library"
			else if libraryCheck is {} and playlistClass is not user playlist then
				return "add to library"
			else
				try
					get location of item 1 of libraryCheck
					return ""
				on error
					return "download"
				end try
			end if
		on error
			return ""
		end try
	end tell
else
	return ""
end if
2 Likes