Skip to content

Instantly share code, notes, and snippets.

@fixlr
Created May 19, 2011 15:37
Show Gist options
  • Save fixlr/981056 to your computer and use it in GitHub Desktop.
Save fixlr/981056 to your computer and use it in GitHub Desktop.
Launch the OSX Color Picker and copy a HEX value to the clipboard
-- Launch the OSX Color Picker and copy a HEX value to the clipboard.
-- From: http://strawhousepig.net/index.php?focus=19
set theColor to (choose color)
set the clipboard to my RGB2HTML(theColor)
on RGB2HTML(RGB_values)
-- NOTE: this sub-routine expects the RBG values to be from 0 to 65536
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 RGB_values
set this_value to (item i of the RGB_values) 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 RGB2HTML
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment