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