Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Forked from mariocesar/chose_color.scpt
Created March 30, 2020 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save james2doyle/b446466adc4e73605982a1101aa2a402 to your computer and use it in GitHub Desktop.
Save james2doyle/b446466adc4e73605982a1101aa2a402 to your computer and use it in GitHub Desktop.
Apple Script / Start the color choose, convert the selected color to HEX and copy to the clipboard
# Open the color picker
on convertRGBColorToHexValue(theRGBValues)
set theHexList to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
set theHexValue to ""
repeat with a from 1 to count of theRGBValues
set theCurrentRGBValue to (item a of theRGBValues) div 256
if theCurrentRGBValue is 256 then set theCurrentRGBValue to 255
set theFirstItem to item ((theCurrentRGBValue div 16) + 1) of theHexList
set theSecondItem to item (((theCurrentRGBValue / 16 mod 1) * 16) + 1) of theHexList
set theHexValue to (theHexValue & theFirstItem & theSecondItem) as string
end repeat
return ("#" & theHexValue) as string
end convertRGBColorToHexValue
# {65535, 0, 0} == red
set theRGBValues to (choose color default color {65535, 0, 0})
set hexValue to (convertRGBColorToHexValue(theRGBValues))
set the clipboard to hexValue as text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment