My script stopped working

I have an old iTunes script that has worked reliably for years, and now it doesn’t. It still runs alright when saved as an application, but when the same script is run in ScriptEditor, it returns this error:

Result:
error “iTunes got an error: Can’t get some playlist whose special kind = music.” number -1728 from some playlist whose special kind = music

I’m looking for help on finding what might have changed.

I can post the entire script, but it’s kind of long.

Hi,

the reason is a terminology clash (enumeration music in media kind and Music in special kind).

Apparently the compiler prefers the former (lowercase) syntax

To work around the problem write the raw syntax

«constant eSpKkSpZ»

which will be compile correctly.

Well, or COURSE! How could I have overlooked that? «constant eSpKkSpZ» was the first thing I should have tried :slight_smile: Thanks, StefanK. When I substitute «constant eSpKkSpZ» for music, and then Save, ScriptEditor changes it back to Music. But it works.

This script is pretty neat and I’ll post the corrected version below. This came from one I found over at http://www.dougscripts.com/itunes/ back around Snow Leopard time, so it’s survived multiple OS’s plus numerous iTunes updates, and it just keeps on ticking. This is the first minor breakage.


--adapted from:
--http://www.dougscripts.com/itunes/

(*

Use the name of the artist from the currently playing iTunes track to compile a playlist, named after the artist, with all the tracks in the whole library which contain that artist.  Then switch over to the new playlist and keeps on playing.

*)

property path_to_xml : "~/Music/iTunes/iTunes Library.xml"
property playlistSuffix : ""

global thisName
global thisArtist
global thisAlbum
global mainLibrary

tell application "iTunes"
	if player state is stopped then error number -128
	set thisArtist to the artist of current track
	set thisName to the name of current track
	set thisAlbum to the album of current track
	set mainLibrary to (get some playlist whose special kind is Music)  -- «constant eSpKkSpZ» from StefanK
end tell

tell application "Finder"
	set frontapp to the name of every process whose frontmost is true
end tell
set frontapp to item 1 of frontapp

tell application "iTunes"
	if (class of front window is browser window) or (class of front window is playlist window) then
		set thePlaylist to mainLibrary
	end if
	-- get a list of all tracks by artist
	try
		set searchTracks to search thePlaylist for thisArtist only artists
	on error --Artist field is blank  -- this can't happen, there has to be at least one because we're listening to it
		set searchTracks to ""
	end try
	
	if not searchTracks = "" then
		set foundTracks to {}
		repeat with nextTrack in searchTracks
			if artist of nextTrack is thisArtist then set end of foundTracks to nextTrack
		end repeat
		
		-- name of new playlist
		set artistPlaylist to ("*" & thisArtist & playlistSuffix)
		repeat
			try
				delete user playlist artistPlaylist
			on error
				exit repeat
			end try
		end repeat
		make new playlist with properties {name:artistPlaylist}
		
		-- establish variable for new playlist
		set randomPlaylist to playlist artistPlaylist
		
		-- get all tracks by selected artist in foundTracks	
		repeat with nextTrack in foundTracks
			duplicate nextTrack to randomPlaylist
		end repeat
		set view of front window to randomPlaylist
		play randomPlaylist
	end if
end tell

to get_artist_list()
	with timeout of 5000 seconds
		set the_command to "grep \"<key>Artist</key>\" " & path_to_xml & ¬
			" | sort -fd | uniq | sed -e 's/<key>Artist<\\/key><string>//g' -e 's/<\\/string>//g' " & ¬
			"-e 's/&/\\&/g' -e 's/	//g' | tr '
' '	'"
		set artist_list to text_to_list((do shell script the_command), "	")
		if last item of artistList is "" then set artistList to items 1 thru -2 of artistList
	end timeout
end get_artist_list

on text_to_list(txt, delim)
	set saveD to AppleScript's text item delimiters
	try
		set AppleScript's text item delimiters to {delim}
		set theList to every text item of txt
	on error errStr number errNum
		set AppleScript's text item delimiters to saveD
		error errStr number errNum
	end try
	set AppleScript's text item delimiters to saveD
	return (theList)
end text_to_list