Skip to content

Instantly share code, notes, and snippets.

@ValentinWalter
Created October 5, 2021 18:50
Show Gist options
  • Select an option

  • Save ValentinWalter/9d7e632bd5dd0cb06ae6322c950e3f54 to your computer and use it in GitHub Desktop.

Select an option

Save ValentinWalter/9d7e632bd5dd0cb06ae6322c950e3f54 to your computer and use it in GitHub Desktop.
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
set theRGBValues to (choose color)
set the clipboard to convertRGBColorToHexValue(theRGBValues)
@ValentinWalter
Copy link
Copy Markdown
Author

This opens the native macOS color picker and copies the hex string to the clipboard.

  1. Open this file in Script Editor
  2. Choose File > Export…
  3. Make sure to choose File Format: Application
  4. Save to your ~/Applications folder

There's more potential here, such as setting up a global keyboard shortcut or letting the user choose which format to copy. Contributions/comments welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment