Skip to content

Instantly share code, notes, and snippets.

@w-A-L-L-e
Created May 31, 2022 13:01
Show Gist options
  • Save w-A-L-L-e/412a88c09bd3b6773b3fa8f51a167763 to your computer and use it in GitHub Desktop.
Save w-A-L-L-e/412a88c09bd3b6773b3fa8f51a167763 to your computer and use it in GitHub Desktop.
Color picker using cliclick log color in both r g b and hex string.
#!/usr/bin/env python3
from time import sleep
import subprocess
# brew install cliclick
def hexcol(c):
hc = f'{hex(c)}'.replace("0x","")
if(len(hc)<2):
hc = f'0{hc}'
return hc
def main():
while True:
color_string = subprocess.run(['cliclick', 'cp:.'], stdout=subprocess.PIPE).stdout.decode('utf-8')
colors_rgb = color_string.replace("\n","").split(" ")
r = int( colors_rgb[0] )
g = int( colors_rgb[1] )
b = int( colors_rgb[2] )
hexcolor = f'#{hexcol(r)}{hexcol(g)}{hexcol(b)}'
print("red: {:>3}, green: {:>3}, blue: {:>3} - hex: {}".format(r,g,b,hexcolor))
sleep(1)
if __name__ == '__main__':
main()
@w-A-L-L-e
Copy link
Author

Example:

$ python colorpicker.py 
red:   5, green:   2, blue:   7 - hex: #050207
red:  25, green:  25, blue:  25 - hex: #191919
red: 244, green: 245, blue: 245 - hex: #f4f5f5
red: 244, green: 245, blue: 245 - hex: #f4f5f5
red:  22, green:  27, blue:  34 - hex: #161b22
red:  22, green:  27, blue:  34 - hex: #161b22

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