Created
May 31, 2022 13:01
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: