iTunes get every track whose artist contains string problem

hello everybody,

this is a very strange problem, i could not resolve nor understand:
i am trying to get the name of every track whose artist is a certain string.
this works great when the artist is taken from the name of the selected track in itunes.
it doesn˜t work if the artist is entered in a dialog window by the user.

i can˜t see why, tried various class types for the artist (utxt, list, text, string)
still i couldn’t get it to work, please help!

jns

www.uptunes.blogspot.com

try
	tell application "iTunes"
		set fixed indexing to false
		set myCache to item 1 of artist of selection
		-- display dialog class of myCache
		set myLTracks to name of every track of library playlist 1 whose artist is myCache
	end tell
on error
	display dialog "Enter an artists name." default answer "" with icon 1
	set myCache to text returned of result
	if myCache is "" then error number -128
	tell application "iTunes"
		set myLTracks to name of every track of library playlist 1 whose artist is myCache
	end tell
end try

Hi,

the script works correctly unless no track matches the entered string.
You can solve the problem catching the error


try
	tell application "iTunes"
		set fixed indexing to false
		set myCache to item 1 of artist of selection
		-- display dialog class of myCache
		set myLTracks to name of every track of library playlist 1 whose artist is myCache
	end tell
on error
	display dialog "Enter an artists name." default answer "" with icon 1
	set myCache to text returned of result
	if myCache is "" then error number -128
	tell application "iTunes"
		try
			set myLTracks to name of every track of library playlist 1 whose artist is myCache
		on error
			display dialog "No matches found"
		end try
	end tell
end try

well, i see, that˜s why it always worked when it got the artist directly from itunes.
ha, how stupid of me.

thanks!
jns