I wrote a script using 2 handlers I found online. It worked beautifully on latest Catalina. However, it runs strange and flaky on Monterey. So I wrote a test script using the same handlers with the same result - good on Catalina, randomly returns the wrong answer on Monterey.
set yrow to {327, 371, 415, 459, 503, 547}
set xrow to {2589, 2633, 2677, 2721, 2765}
repeat with ic from 1 to 6
repeat with i from 1 to 5
set pixelAddress to {item i of xrow, item ic of yrow}
set cvec to getPixelColor(pixelAddress)
(*
delay 0.1
set GR1 to (item 2 of cvec) + 3
set RD1 to (item 1 of cvec) + 3
if ((item 2 of cvec) > RD1) then
set item i of score to 1
else if ((item 1 of cvec) > GR1) then
set item i of score to 2
else
set item i of score to 0
end if
*)
display dialog ((((((ic as text) & " " & i as text) & "
" & item 1 of pixelAddress as text) & " " & item 2 of pixelAddress as text) & "
" & item 1 of cvec as text) & " " & item 2 of cvec as text) & " " & item 3 of cvec as text
end repeat
end repeat
on getPixelColor({x, y})
set hexColor to do shell script "screencapture -R" & x & "," & y & ",1,1 -t bmp $TMPDIR/test.bmp &&
xxd -p -l 3 -s 54 $TMPDIR/test.bmp |
sed 's/\\(..\\)\\(..\\)\\(..\\)/\\3\\2\\1/'"
return HEX2RGB(hexColor)
end getPixelColor
on HEX2RGB(RGB_Hex)
set RGB_List to {}
set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
set HEXpairs to {{characters 1 thru 2 of RGB_Hex as string}, {characters 3 thru 4 of RGB_Hex as string}, {characters 5 thru 6 of RGB_Hex as string}}
repeat with NextPair in HEXpairs
repeat with x from 1 to (count of item in hex_list)
if ((character 1 of (NextPair as string))) is ((item x of hex_list) as string) then
set x to (x - 1)
exit repeat
end if
end repeat
repeat with y from 1 to (count of item in hex_list)
if ((character 2 of (NextPair as string))) is ((item y of hex_list) as string) then
set y to (y - 1)
exit repeat
end if
end repeat
set ThisNum to ((x * 16) + (y * 1)) -- this gives 8 bit RBG
set RGB_List to RGB_List & ThisNum
end repeat
return RGB_List
end HEX2RGB
The display dialog always returns the correct color info on Catalina. But on Monterey, every so often it returns 255, 0, 0
I know it is not the correct. I run the test on each system using pretty much the same source.
To be fair, while I understand AppleScript, I do not know anything about running a shell script. As I said the handlers were copied from the web. Does anyone know why it should perform differently on Monterey - and randomly flakey also?