Not really satisfied with the other solution, I tried my ImageMagick idea. Works fine for me! (Depends on xclip, ImageMagick, xdotool, notify-send)
#!/bin/sh
# Get hex rgb color under mouse cursor, put it into clipboard and create a
# notification.
eval $(xdotool getmouselocation --shell)
IMAGE=`import -window root -depth 8 -crop 1x1+$X+$Y txt:-`
COLOR=`echo $IMAGE | grep -om1 '#\w\+'`
echo -n $COLOR | xclip -i -selection CLIPBOARD
notify-send "Color under mouse cursor: " $COLOR
EDIT:
Now using Gnome Shell, I have problems with the above solution (import won't take a screenshot of the visible windows, I don't know why. Hints are welcome). An alternative is to use a (fast) screenshot taker like scrot
and use convert
instead of import
:
#!/bin/sh
# Get hex rgb color under mouse cursor, put it into clipboard and create a
# notification.
scrot --overwrite /tmp/copycolor.png
eval $(xdotool getmouselocation --shell)
IMAGE=`convert /tmp/copycolor.png -depth 8 -crop 1x1+$X+$Y txt:-`
COLOR=`echo $IMAGE | grep -om1 '#\w\+'`
echo -n $COLOR | xclip -i -selection CLIPBOARD
notify-send "Color under mouse cursor: " $COLOR
Update 2020: Newer versions of scrot require the "--overwrite" option to be set for this to work.