我需要获取鼠标光标下方像素的十六进制代码颜色。有很多不错的GUI工具来解决此任务,但是我需要一种简单的命令行方式来获取颜色,以便可以在Shell脚本中使用该解决方案。
可能我可以使用ImageMagick拍摄(一个像素?)屏幕截图并从中提取颜色(我可以使用来获取位置xdotool
)。也许有一个更简单的解决方案。
有什么建议么?
你当然可以。但是您需要另一个linux软件包。如果您使用的是Ubuntu,只需发出:
sudo apt-get install xdotool grabc
Run Code Online (Sandbox Code Playgroud)
然后运行grapc,但将其作为背景
grabc &
Run Code Online (Sandbox Code Playgroud)
然后使用xdotool执行mouseclick
xdotool click 1
Run Code Online (Sandbox Code Playgroud)
点击将被grapc的光标捕获,并且背景处理将输出颜色。
但也许无法通过脚本运行。为此,您可能需要在Ubuntu论坛上查看此主题。
或者,如果您不介意,则可以按照此处所述用python来完成。
我对其他解决方案不太满意,因此尝试了ImageMagick的想法。对我来说很好!(取决于xclip,ImageMagick,xdotool,通知发送)
#!/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
Run Code Online (Sandbox Code Playgroud)
编辑:
现在使用Gnome Shell,上述解决方案存在问题(导入不会获取可见窗口的屏幕截图,我不知道为什么。欢迎提示)。一种替代方法是使用(快速)屏幕截图获取者,例如scrot
和使用convert
而不是import
:
#!/bin/sh
# Get hex rgb color under mouse cursor, put it into clipboard and create a
# notification.
scrot /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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4006 次 |
最近记录: |