Quotes in applescript

tell application "iTunes"
	set playlistlist to (name of playlists)
end tell
choose from list playlistlist
tell application "iTunes"
	play playlist result
end telll

Hi everyone,

I’m having a little issue with the small script above. I want to select a playlist from a list of all of them and then instruct iTunes to play it. However, I keep getting this:

error “iTunes got an error: A descriptor type mismatch occurred.”

I guess it’s because the result I’m asking doesn’t have quotation marks. Where I’d normally write: tell application “iTunes”, play playlist “defaultplaylist”, end tell. The script is just reading: play playlist defaultplaylist.

So how do I get the script to either preserve or add quotation marks?



Hi. Welcome to MacScripter.

choose from list often catches people out. It returns a list of the chosen items, even when there’s only one item. Also, for historical reasons, it returns false when the “Cancel” button’s clicked, instead of generating error number -128 (“User canceled.”) to stop the script. So the first thing to try would be to code round this:

tell application "iTunes"
	set playlistlist to (name of playlists)
end tell

set theChoice to (choose from list playlistlist)
-- If 'false' is returned, generate a "User canceled." error.
if (theChoice is false) then error number -128
-- Otherwise it's a list. Get the first (or only) item.
set chosenName to item 1 of theChoice

tell application "iTunes"
	play playlist chosenName
end tell

Hi Nigel,

Thank you, that has worked perfectly!