Reputation: 1613
How can we check the color of a determined pixel(x,y) and, if it is equal to a certain value, run a bash script.
In particular I'd like to write a script that:
I know only how to complete step 3, the first 2 steps are out of my coding skill. Can you help me?
Upvotes: 4
Views: 2903
Reputation: 3444
As for checking for keystrokes, I use this command line tool:
http://www.klieme.ch/pub/checkModifierKeys.zip
, which is discussed on macscripter.net (sorry, can't post this as link). This command line command is utilized in a similar fashion to what I describe below ("do shell script"). Another command line tool is used to get the pixel position of the mouse:
www.bluem.net/en/mac/cliclick/
(again, sorry for inability to post this as link).
For getting pixel color ...
See my blog post about using python for this (my method is based on similar solutions): http://thechrisgreen.blogspot.com/2013/04/python-script-for-getting-pixel-color.html
I have an AppleScript script that does "do shell script" with this python script, sets a variable "rgb" to the (string) result, then does
run script rgb
which gets you a list like
{255,255,255}
Seeing this rather late in the game ... this is for future surfers I guess ...
Upvotes: 1
Reputation: 27613
I don't know about the first step, but you could take a screenshot and use ImageMagick to print the colors of pixels.
tmp=/tmp/$(uuidgen).png
trap "rm $tmp" exit
screencapture $tmp
/usr/local/bin/convert $tmp[1x1+1000+500] $tmp[1x1+1100+500]\
$tmp[1x1+1000+510] $tmp[1x1+1100+510] txt: | grep '#FFFFFF' || exit
Upvotes: 3