get a browser-safe HTML color with the standard Color Picker

set RGBlist to choose color
set htmlColor to "" as Unicode text
repeat with i in RGBlist
	tell ((round ((i div 256) / 50) rounding as taught in school) * 50) to set RGBcolor to it + (it div 50)
	-- the perl script does the dec -> hex conversion
	set htmlColor to htmlColor & text -2 thru -1 of ("0" & (do shell script "perl -e 'printf(\"%X\", " & RGBcolor & ")'"))
end repeat
htmlColor --> e.g. 6600CC

There is not a “ROFL” large enough to convey what I’m doing right now. Oh, Apple, you never cease to amuse.

Never seen this bit of the language before. Thanks, Stefan. :slight_smile:

Hi Mikey,

the line
tell ((round (i div 256) / 50) * 50) to set RGBcolor to it + (it div 50)
does the same, but I really love this expression :slight_smile:

That’s why it’s hysterical. In reality, it’s not good practice, but it’s still really funny to imagine that day in the Apple offices:

“Hey Jim, let’s add some comical verbosity to the command.”

“Bob, I think you’re on to something here.”

The reason the conditional “as taught in school” was added was to make the results of a rounding match with what is/was generally taught in school. This would be instead of always rounding up or down.

AppleScript was meant to be very verbose, with phrases standing in for “geek speak” in a lot of places to make scripting more accessible (contrast AppleScript with Frontier, which shipped before AppleScript). Of course, these days, everyone is complaining that AppleScript doesn’t have enough “geek speak” for its functions, which should mean switch to a different language such as PERL (which has Apple Event bridge support I believe). There is also a JavaScript OSA component that can be mixed in with AppleScript.

Great Code StefanK, It was helpful for a small AS App I made…


Very simple and handy, thanks for the code!