Check if you already have iTunes Store Tracks in your Music Library

I wanted to be able to check if Tracks I am looking at in the iTunes Store where already in my Music library, and so save me purchasing songs twice.¨¨The Script works on the full list in the track view.¨I tested with 150 tracks (madonna) and it did not take too long.
Note: To get correct results you must be in the store, when in the store the name column is second from left and artist column is fourth from left
see top of script for example.
You can use it in the Shopping Cart when showing all the tracks in the album folders (if you have them) , but if you have an album, the script will include the album name/s in the results


The Script actually came in handy a couple of days ago with a second use, when I was downloading 3 albums from the Store, my iTunes crashed,¨and it was clear, some of the songs did not download… AHHHH¨¨I ran the script on the iTunes Store list, and got the track names of the missing songs just like that.
Selected them in the dialog, And used the text output to paste into the email which I needed to send to apple. Nice.¨¨Apple sorted it out very quickly.

I posted originally here in the OS X section , for a quick review to see if any one could suggest any changes needed. Stefank supplied a bit of code for compatibility and a suggestion related to the end result (Thanks)

Please feel free to add to this, as i am sure it can be better.

(* To get correct results when in the store the name column is second from left and artist   column is fourth from left 

example:

|	| Name  			| Time	| Artist			| Album					|
| 1	| Hollywood		| 5:08	| The Cranberries	| To the Faithul Departed	|
| 2	| salvation		| 2:23	| The Cranberries	| To the Faithul Departed	|
 *)


set AppleScript's text item delimiters to ""
tell application "System Events" to tell process "iTunes"
	
	try
		--tell window "iTunes" to tell scroll area 1 of splitter group 1 to tell outline 1
		tell window "iTunes" to tell outline 1 of (get 1st scroll area of splitter group 1 whose static texts of outline 1 is {})
			set SongList to {}
			set biglist to {}
			set bigTracklist to {}
			set Yestrack to 0
			set InLibList to {}
			set NotInLibList to {}
			
			(* get name and artist using GUI scripting from iTunes Store list*)
			set SongList to value of text field 1 of every row
			set ArtistList to value of text field 3 of every row
			set trackcountStore to (count of SongList) as string
			tell application "iTunes"
				
				repeat with i from 1 to number of items in SongList
					(* if  name  contains explicit, remove it*)
					set this_song to item i of SongList
					set this_artist to item i of ArtistList
					set oldDelims to AppleScript's text item delimiters
					set AppleScript's text item delimiters to {", explicit"}
					set this_song to text item 1 of this_song as string
					set AppleScript's text item delimiters to oldDelims
					try
						(* find matching song name and artist in your library*)
						set myLibTracks to (name of tracks of library playlist 1 whose name contains this_song and artist contains this_artist)
						set myLibTracksArtist to (artist of tracks of library playlist 1 whose name contains this_song and artist contains this_artist)
						
						set trackcount to count of myLibTracks
						(* there maybe more than one match in your library*)
						if trackcount is greater than 1 then
							repeat with i from 1 to number of items in myLibTracks
								copy (item i of myLibTracks) & " by " & item i of myLibTracksArtist & " (Y)" as string to end of bigTracklist
								set Yestrack to Yestrack + 1
							end repeat
							
						else
							
							copy (myLibTracks) & " by " & myLibTracksArtist & " (Y)" as string to end of bigTracklist
							set Yestrack to Yestrack + 1
						end if
					on error
						(* If no match in your library, an error will occure, so use it to get no match list*)
						copy (this_song) & " by " & this_artist & " (N)" to end of bigTracklist
					end try
					
				end repeat
				set Yestrack to Yestrack as string
				(* show results*)
				repeat with i from 1 to number of items in bigTracklist
					set this_lib_item to item i of bigTracklist
					if this_lib_item contains "(Y)" then
						copy this_lib_item to end of InLibList
					else
						copy this_lib_item to end of NotInLibList
					end if
				end repeat
				set libcount to (count of items in InLibList) as string
				set notlibcount to (count of items in NotInLibList) as string
				set mixedcount to (count of items in bigTracklist) as string
				log mixedcount
				display dialog "Show" buttons {mixedcount & " Mixed Results", libcount & " In Library", notlibcount & " Not in library"} default button 3
				set the button_pressed to the button returned of the result
				if the button_pressed is mixedcount & " Mixed Results" then
					set yourSelection to choose from list bigTracklist with prompt " Tracks Found or Not in you Library" with multiple selections allowed
				else if the button_pressed is libcount & " In Library" then
					set yourSelection to choose from list InLibList with prompt libcount & " out of " & trackcountStore & " Tracks search for  FOUND in you Library" with multiple selections allowed
					
				else
					set yourSelection to choose from list NotInLibList with prompt notlibcount & " out of " & trackcountStore & " Tracks search for NOT found in you Library" with multiple selections allowed
					
				end if
				
				if yourSelection is not "" then
					set this_line to ""
					repeat with i from 1 to number of items in yourSelection
						set this_line to this_line & item i of yourSelection & return as string
					end repeat
					(* make a text doc, with items you chose *)
					tell application "TextEdit"
						activate
						make new document
						set the text of the front document to this_line
					end tell
				end if
			end tell
		end tell
	on error mssg
		if mssg contains "NSReceiverEvaluationScriptError: 4" then
			display dialog " Make sure you are in the iTunes Store and " & return & return & "viewing a song list, before you run this script."
		end if
	end try
	
end tell