diff --git a/color-picker b/color-picker new file mode 100755 index 0000000..0062681 --- /dev/null +++ b/color-picker @@ -0,0 +1,38 @@ +#!/bin/sh +# Modification of https://github.com/jgmdev/wl-color-picker + +# Check if running under wayland. +if [ "$WAYLAND_DISPLAY" = "" ]; then + echo "Error: No wayland session found." + exit 1 +fi + +# Get color position +position=$(slurp -b 00000000 -p) + +# Sleep at least for a second to prevet issues with grim always +# returning improper color. +#sleep 1 + +# Store the hex color value using graphicsmagick or imagemagick. +if type gm &> /dev/null; then + color=$(grim -g "$position" -t png - \ + | gm convert - -format '%[pixel:p{0,0}]' txt:- \ + | tail -n 1 \ + | rev \ + | cut -d ' ' -f 1 \ + | rev + ) +else + color=$(grim -g "$position" -t png - \ + | convert - -format '%[pixel:p{0,0}]' txt:- \ + | tail -n 1 \ + | cut -d ' ' -f 4 + ) +fi + +# Copy to clipboard +echo $color | wl-copy -n + +# Display as a notification +notify-send "Copied to clipboard" $color