Color picker

This commit is contained in:
Out Of Ideas 2024-04-09 22:01:06 -05:00
parent e51857c4a4
commit 4f5ee21ba2
1 changed files with 38 additions and 0 deletions

38
color-picker Executable file
View File

@ -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