Error: window doesn't understand subroutine (-1708)

Ok I am new to applescript, you have your warning. I think this is in the right category, if not I am very sorry. … anyway… on to the issue at hand…
I am trying to write a simple applescript program (a color thing), at the moment I am having trouble getting the color from a color well translated into HTML Hex and put in a text field (if that makes sense)

The full error:

window "ColorThingy" doesn't understand the RBG2HTML message. (-1708)

my applescript:

on awake from nib theObject
	if theObject is equal to the window "ColorThingy" then
		set visible of color panel to true -- Show the color panel on launch
		tell window "ColorThingy"
			set rgbValue to the color of color well "ColorWellOne" -- returns a number
			set contents of text field "TextOne" to RBG2HTML(rgbValue)
		end tell
	end if
end awake from nib

This has me utterly confused, and being new to applescript that isn’t surprising. Everything seems to go fine until it gets to the line:

set contents of text field "TextOne" to RBG2HTML(rgbValue)

This would lead me normally to believe that my subroutine is at fault:


on RBG2HTML(rgbValue)
	-- NOTE: this sub-routine expects the RBG values to be from 0 to 65536
	-- Subroutine from: http://www.apple.com/applescript/guidebook/sbrt/pgs/sbrt.04.htm
	set the hex_list to ¬
		{"0", "1", "2", "3", "4", "5", "6", "7", "8", ¬
			"9", "A", "B", "C", "D", "E", "F"}
	set the the hex_value to ""
	repeat with i from 1 to the count of the rgbValue
		set this_value to (item i of the rgbValue) div 256
		if this_value is 256 then set this_value to 255
		set x to item ((this_value div 16) + 1) of the hex_list
		set y to item (((this_value / 16 mod 1) * 16) + 1) of the hex_list
		set the hex_value to (the hex_value & x & y) as string
	end repeat
	return ("#" & the hex_value) as string
end RBG2HTML

but that subroutine not only was written by apple (e.g. its good!) it also works in a separate applescript, just not in my simple program…

If anyone can help a very confused programmer out, it would be most appreciated :smiley:

Greetings… and welcome. :slight_smile:

You simply need to move the code calling the subroutine out of the tell block of the window.

on awake from nib theObject
	if theObject is window "ColorThingy" then
		set visible of color panel to true -- Show the color panel on launch
		set rgbValue to color of color well "ColorWellOne" of window "ColorThingy" -- returns a number
		set contents of text field "TextOne" of window "ColorThingy" to RBG2HTML(rgbValue)
	end if
end awake from nib

Good luck…
j

thank you for your help, but I am still getting an error (a new one):

once again, my applescript:


on awake from nib theObject
	if theObject is window "ColorThingy" then
		set visible of color panel to true -- Show the color panel on launch 
		set rgbValue to color of color well "ColorWellOne" of window "ColorThingy" -- returns a number 
		set contents of text field "TextOne" of window "ColorThingy" to RBG2HTML(rgbValue)
	end if
end awake from nib

on RBG2HTML(rgbValue)
	-- NOTE: this sub-routine expects the RBG values to be from 0 to 65536
	-- http://www.apple.com/applescript/guidebook/sbrt/pgs/sbrt.04.htm
	set the hex_list to ¬
		{"0", "1", "2", "3", "4", "5", "6", "7", "8", ¬
			"9", "A", "B", "C", "D", "E", "F"}
	set the the hex_value to ""
	repeat with i from 1 to the count of the rgbValue
		set this_value to (item i of the rgbValue) div 256
		if this_value is 256 then set this_value to 255
		set x to item ((this_value div 16) + 1) of the hex_list
		set y to item (((this_value / 16 mod 1) * 16) + 1) of the hex_list
		set the hex_value to (the hex_value & x & y) as string
	end repeat
	return ("#" & the hex_value) as string
end RBG2HTML

help is as always, needed and very much appreciated :wink:

That error is probably due to referencing an item that is either not named properly, or does not exist. Make sure that your AS names (not the window titles or instance names) are set according to the names you reference in your script. Make sure I didn’t accidentally change one of the names from your original names when I posted the code. :o The subroutine code and the awake from nib handler both appear to be identical to that which I tested in my sample app, so a connection or name in IB is likely the cause.

j

You were right, I didn’t name my text box correctly, thank you for your help :smiley:

I am trying to figure something out, perhaps you know… Is there a way to update the text field every time the color in the color well changes? at the moment I am using a box, every time the mouse hovers over this box, the field updates, but it is kind of tedious … is there another way?
The box code:

on mouse entered theObject event theEvent
	set rgbValue to color of color well "ColorWellOne" of window "ColorThingy" -- returns a number 
	set contents of text field "TextOne" of window "ColorThingy" to RBG2HTML(rgbValue)
end mouse entered

looking at the options for the color well on interface builder I was thinking that maybe ther is a way to use “on action” but that is really just a guess (and it isn’t an option in interface builder for color well, so i don’t know if it would be valid), and i tried it:

if theObject is color well "ColorWellOne" of window "ColorThingy" then
		set rgbValue to color of color well "ColorWellOne" of window "ColorThingy" -- returns a number 
		set contents of text field "TextOne" of window "ColorThingy" to RBG2HTML(rgbValue)
	end if

and it did nothing, (not even an error :o )

I realize this is getting dangerously to the anoying “can you do it for me???” but I am trying to avoid that at all costs, i promise :wink: …Anyway input would be appreciated