Sway Colour Picker

Hey friends.

I just came across a little ditty for hacking together a colour picker for the Wayland-based tiling window manager Sway. I use the keybinding Super+Shift+P and you select a 1x1 pixel wide image (effectively wherever you click) and the color in hex format (e.g., #rrggbb) will be added to you clipboard. I wrote it up briefly on my blog, but I figured I’d save you the gist:

You’ll need to have installed grim, slurp, wl-clipboard and imagemagick for this key binding to work.

Add the following to your config file (modify the binding as you see fit):

bindsym $mod+Shift+p exec grim -g "$(slurp -p)" -t ppm - | convert - -format '%[pixel:p{0,0}]' txt:- | tail -n 1 | cut -d ' ' -f 4 | wl-copy

All praise ought to go to Matthias Braun on StackExchange for coming up with this :smiley:

1 Like