Uknown Error

i can’t for the life of me figure out why i get this error, “iTunes got an error: Unknown object type. (-2700)”

here is the code (sry, it’s a little long):

property contentNaa : "Title-Album-Artist"


on launched theObject
	(**iSuck**)
end launched

on playThing()
	set play_thing to ""
	try
		tell application "iTunes"
			if player state is playing then
				set play_thing to ("true" as string)
			else
				set play_thing to ("false" as string)
			end if
		end tell
	end try
	if play_thing is "true" then
		set image of image view 11 of window "main" to load image "pause"
	else
		set image of image view 11 of window "main" to load image "play"
	end if
end playThing

on jdp()
	try
		tell application "iTunes"
			set nam to name of current track
			set artis to artist of current track
			set albu to album of current track
		end tell
	end try
	if contentNaa is "nam" then
		try
			set contents of text field "naa" of window "main" to artis
			set contentNaa to ("artis" as string)
		end try
	else if contentNaa is "artis" then
		try
			set contents of text field "naa" of window "main" to albu
			set contentNaa to ("albu" as string)
		end try
	else if contentNaa is "albu" then
		try
			set contents of text field "naa" of window "main" to nam
			set contentNaa to ("nam" as string)
		end try
	else
		try
			set contents of text field "naa" of window "main" to contentNaa
			set contentNaa to ("nam" as string)
		end try
	end if
	
end jdp

on shuffleC()
	set shuffler to ""
	try
		tell application "iTunes"
			set shuffler to shuffle of current playlist
			if shuffler is true then
				set shuffler to ("false" as string)
			else
				set shuffler to ("true" as string)
			end if
		end tell
	end try
	if shuffler is "false" then
		set image of image view 9 of window "main" to load image "on_shuffle"
	else
		set image of image view 9 of window "main" to load image "shuffle"
	end if
end shuffleC

on repeatC()
	set repeat_type to ""
	try
		tell application "iTunes"
			set arepeat to the song repeat of current playlist
			set repeat_type to ""
			if arepeat is one then
				set repeat_type to ("one" as string)
			else if arepeat is off then
				set repeat_type to ("off" as string)
			else
				set repeat_type to ("all" as string)
			end if
		end tell
	end try
	if repeat_type is "one" then
		set image of image view 8 of window "main" to load image "on_repeat_one"
	else if repeat_type is "off" then
		set image of image view 8 of window "main" to load image "on_repeat"
	else
		set image of image view 8 of window "main" to load image "repeat"
	end if
end repeatC

on idle theObject
	set text color of text field "naa" of window "main" to "black"
	tell application "Finder"
		set x to name of every process
	end tell
	if "iTunes" is in x then
		try
			jdp()
			playThing()
			shuffleC()
			repeatC()
		on error err
			log err
		end try
		tell application "iTunes"
			set timer to ""
			if player state is playing then
				set timer to "10"
			else
				set timer to "20"
			end if
		end tell
		return timer
	else
		return 10
		set image of image view 11 of window "main" to load image "play"
		set contents of text field "naa" of window "main" to contentNaa
		
	end if
end idle

on clicked theObject
	(*Add your script here.*)
end clicked

on artwork()
	try
		tell application "iTunes"
			set trackthing to current track
			set theArt to data of artwork 1 of trackthing
		end tell
		set tempartwork to ("" & (path to me) & "Contents:Resources:" & "thing.pict") as file specification
		set file_reference to (open for access tempartwork with write permission)
		
		set eof file_reference to 512
		write theArt to file_reference starting at 513
		close access file_reference
		set tempartwork1 to (tempartwork as string)
		set theposixpath to (POSIX path of tempartwork1)
		set image of image view "artworkP" of window "artworkWindow" to load image theposixpath
	on error err
		--close access file_reference
		set image of image view "artworkP" of window "artworkWindow" to load image "case"
		error err
	end try
end artwork

on remove_markup(this_text)
	log "Started cleaning text"
	set myAllowed to {"://", "@"}
	set {myTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {"<"}}
	set these_items to text items of this_text
	set AppleScript's text item delimiters to {">"}
	repeat with my_item in these_items
		if length of text items of my_item is greater than 1 then
			if (text item 1 of my_item) is not in myAllowed then
				set my_item's contents to (text item 2 of my_item)
			else
				set my_item's contents to ("<" & (text items of my_item)) as text
			end if
		end if
	end repeat
	set AppleScript's text item delimiters to myTID
	set clean_text to these_items as text
	--return clean_text
	log "Text Cleaned"
	set new_clean_text to ""
	set y to 0
	repeat with lin in clean_text
		set num to (ASCII number of lin)
		if y is 12 then
			--log "y is 6"
			set new_clean_text to new_clean_text & (ASCII character of num)
		else
			set y to (y + 1)
			--log y
		end if
	end repeat
	log "Removed first 12 lines"
	set contents of text view "lyricText" of scroll view "lyricT" of window "lyric" to new_clean_text
end remove_markup


on awake from nib theObject
	artwork()
	try
		tell application "iTunes"
			set artis to artist of current track
			set nam to name of current track
		end tell
		set ur to "http://www.azlyrics.com/lyrics/"
		set new_artis to ""
		set new_nam to ""
		repeat with char1 in artis
			set num1 to (ASCII number of char1)
			if num1 is greater than 62 and num1 is less than 91 then set num1 to (num1 + 32)
			if num1 is greater than 47 and num1 is less than 58 then set new_artis to new_artis & (ASCII character of num1)
			if num1 is greater than 96 and num1 is less than 123 then set new_artis to new_artis & (ASCII character of num1)
		end repeat
		
		repeat with char2 in nam
			set num2 to (ASCII number of char2)
			if num2 is greater than 62 and num2 is less than 91 then set num2 to (num2 + 32)
			if num2 is greater than 47 and num2 is less than 58 then set new_nam to new_nam & (ASCII character of num2)
			if num2 is greater than 96 and num2 is less than 123 then set new_nam to new_nam & (ASCII character of num2)
		end repeat
		
		set new_url to (ur & new_artis & "/" & new_nam & ".html") as string
		log new_url
		
		set myHtml to do shell script "curl " & new_url
		log "Curled url"
		set {myDels, AppleScript's text item delimiters} to {{""}, {"</head>"}}
		set myText to text item 2 of myHtml
		set AppleScript's text item delimiters to myDels
		log "Starting Remove_markup"
		set myText to remove_markup(myText)
		--remove_markup()
	on error err
		log "Lyrics not found"
		set contents of text view "lyricText" of scroll view "lyricT" of window "lyric" to "Lyrics not found"
		--display dialog err
	end try
	--remove_markup()
end awake from nib

an alternative solution to this would be a way to make all errors or dialog box’s not appear…anyone know how to do that?

thxs!

As to why you are getting the error, I don’t know exactly but there are a number of things wrong with your script. When does the error occur? Add more log statements to your script so you can see where it is (which handler and also which step within the handler) when the error occurs and you will be better able to correct the issue.

Why do you try to coerce booleans and integers to strings? There is no need to coerce true to “true”, if you are just going to test that the value = “true” later. If it’s true, it’s true.

The idle handler has to return an integer, not a string, why are you having it return a string? The integer returned is the number of seconds to wait before the idle handler is called again.

I haven’t tried it, but I doubt you can just set the color of a text field using the name of the color as a string. Colors are defined by their RGB equivalents (e.g, black = {0, 0, 0}; white = {65535, 65535, 65535}). In any event, this line seems extraneous. Do you allow the user to change the color of the text field? If not, just make sure the text field uses black as the text color in IB and get rid of this line entirely.

Also, when using the “load image” command, according to Apple, you should load the image into a variable and then delete the image after adding it to an image view otherwise it will never be removed from memory.

Aside from all that, there are a lot things that could be optimized. Try this:

property contentNaa : "Title-Album-Artist"

on launched theObject
	(**iSuck**)
end launched

on awake from nib theObject
	my artwork()
	my get_lyrics()
end awake from nib

on idle theObject
	set timer to 10
	tell application "System Events" to set x to name of processes
	if x contains "iTunes" then
		try
			my jdp()
			my playThing()
			my shuffleC()
			my repeatC()
			tell application "iTunes" to if player state is not playing then set timer to 20
		on error err
			log err
		end try
	else
		tell window "main"
			my load_image(the_image, image view 11)
			set contents of text field "naa" to contentNaa
		end tell
	end if
	return timer
end idle

on clicked theObject
	(*Add your script here.*)
end clicked

on playThing()
	set the_image to "play"
	try
		tell application "iTunes" to if (player state is playing) then set the_image to "pause"
	end try
	my load_image(the_image, image view 11 of window "main")
end playThing

on jdp()
	try
		tell application "iTunes" to tell current track to set {nam, artis, albu} to {name, artist, album}
		if contentNaa = "nam" then
			set {the_contents, contentNaa} to {artis, "artis" as Unicode text}
		else if contentNaa = "artis" then
			set {the_contents, contentNaa} to {albu, "albu" as Unicode text}
		else if contentNaa = "albu" then
			set {the_contents, contentNaa} to {nam, "nam" as Unicode text}
		else
			set {the_contents, contentNaa} to {contentNaa, "nam" as Unicode text}
		end if
	on error
		set {the_contents, contentNaa} to {contentNaa, "nam" as Unicode text}
	end try
	set contents of text field "naa" of window "main" to the_contents
end jdp

on shuffleC()
	set the_image to "on_shuffle"
	try
		tell application "iTunes" to if (shuffle of current playlist) then set the_image to "shuffle"
	end try
	my load_image(the_image, image view 9 of window "main")
end shuffleC

on repeatC()
	set the_image to "repeat"
	try
		tell application "iTunes"
			set arepeat to song repeat of current playlist
			if arepeat = one then
				set the_image to "on_repeat_one"
			else if arepeat = off then
				set the_image to "on_repeat"
			end if
		end tell
	end try
	my load_image(the_image, image view 8 of window "main")
end repeatC

on artwork()
	try
		tell application "iTunes" to set theArt to data of artwork 1 of current track
		set tempartwork to ("" & (path to me) & "Contents:Resources:thing.pict") as file specification
		set file_reference to (open for access tempartwork with write permission)
		set eof file_reference to 512
		write theArt to file_reference starting at 513
		close access file_reference
		set the_image to (POSIX path of tempartwork)
	on error err
		log err
		set the_image to "case"
	end try
	my load_image(the_image, image view "artworkP" of window "artworkWindow")
end artwork

on get_lyrics()
	try
		set my text item delimiters to ""
		tell application "iTunes" to tell current track to set {artis, nam} to {artist, name}
		set new_url to ("http://www.azlyrics.com/lyrics/" & my lowercase_no_space(artis) & "/" & my lowercase_no_space(nam) & ".html") as Unicode text
		set myText to (do shell script "curl " & new_url)'s paragraphs as Unicode text
		set myText to my remove_markup(myText)
	on error err
		log err
		set myText to "Lyrics not found"
	end try
	set contents of text view "lyricText" of scroll view "lyricT" of window "lyric" to myText
end get_lyrics

on remove_markup(this_text)
	set this_text to item 2 of my string_to_list(this_text, "</head>")
	set this_text to my snr(this_text, "<BR>", return)'s paragraphs 2 thru -8
	set this_text to my list_to_string(this_text, return)
	set this_text to my snr(this_text, "<", return & "<")
	set this_text to my snr(this_text, ">", ">" & return)'s paragraphs
	repeat with i from 1 to (count this_text)
		set this_item to item i of this_text
		if (this_item starts with "<") then set item i of this_text to ""
	end repeat
	set this_text to my list_to_string(this_text's items 3 thru -1, return)
	repeat while this_text contains (return & return & return)
		set this_text to my snr(this_text, (return & return & return), (return & return))
	end repeat
	return this_text
end remove_markup

on lowercase_no_space(this_string)
	set return_string to {}
	repeat with i from 1 to (count this_string)
		set this_char to this_string's character i
		set ASCII_number to (ASCII number this_char)
		if ASCII_number > 62 and ASCII_number < 91 then
			set end of return_string to (ASCII character (ASCII_number + 32))
		else if (ASCII_number > 47 and ASCII_number < 58) or (ASCII_number > 96 and ASCII_number < 123) then
			set end of return_string to this_char
		end if
	end repeat
	return (return_string as Unicode text)
end lowercase_no_space

on list_to_string(l, d)
	tell (a reference to my text item delimiters)
		set {o, contents} to {contents, d}
		set {l, contents} to {"" & l, o}
	end tell
	return l as Unicode text
end list_to_string

on string_to_list(s, d)
	tell (a reference to my text item delimiters)
		set {o, contents} to {contents, d}
		set {s, contents} to {s's text items, o}
	end tell
	return s
end string_to_list

on snr(the_string, search_string, replace_string)
	tell (a reference to my text item delimiters)
		set {old_tid, contents} to {contents, search_string}
		set {the_string, contents} to {the_string's text items, replace_string}
		set {the_string, contents} to {the_string as Unicode text, old_tid}
	end tell
	return the_string
end snr

on load_image(image_name, image_view)
	set the_image to load image image_name
	set image of image_view to the_image
	delete the_image
end

Jon

thxs for your suggestions!