Snow Leopard Quoting issue

I have been banging my head against this problem for too long now, I eventually ended up hard coding an if…else to bypass it.



set myType to "artist"
set myName to "Weezer"

tell application "iTunes" --Get list from iTunes
	get every track of playlist "Library" whose myType contains myName
end tell


The above does not run because myType is replaced with “artist” instead of just artist, the quotes make iTunes throw an Unknown Object type error.

Anyone know how to get around this? I had it working in Leopard/Tiger with something like:



set myType to "artist"
set myName to "Weezer"

tell application "iTunes" --Get list from iTunes
	return run script "get every track of playlist \"Library\" whose " & myType & " contains \"" & myName & quote
end tell


But under Snow Leopard the quotes aren’t properly escaped and the slashes are actually still there when the run script is called. Adding in the quotes in AppleScript(using & quote &) doesn’t fix the problem either and quoted form of just makes things worse.

I’m baffled as to why Apple would change this, but anyone who can provide a fix or at least some insight into why they changed it I would be most grateful towards.

Seeing the backslashes depends on how you are viewing the string. If you are looking at a string value in the result pane or the event log, those show you how a string would look in AppleScript source code. Those contexts include the backslashes so that you could copy-and-paste the string values into an AppleScript program. But in other contexts (display dialog, data written with write, etc.) the backslashes are not included because they are not actually part of the string (they are only there to allow an inline AppleScript string to include double-quote characters that would ordinarily terminate the inline string value).

To, me it looks like the problem you are seeing is not a problem building the script string, but a change in how Snow Leopard deals with OSAX commands (like run script, which comes from the Standard Additions OSAX).

Try this:

set myType to "artist"
set myName to "Weezer"

--Get list from iTunes
return run script "tell application \"iTunes\" to get every track of playlist \"Library\" whose " & myType & " contains " & quote & myName & quote

Works like a charm, thanks for the help. Feel kinda silly for not thinking of that myself.