@ peavine,
I started testing on Catalina first planning to move on to Monterey if it all works.
I modified your last script to do just one coordinate as so:
use framework "AppKit"
use framework "Foundation"
use framework "QuartzCore"
use scripting additions
set theCoordinates to {{10, 16}} -- x and y screen coordinates
set rgbData to getRGBData(theCoordinates)
-- a summary dialog for testing purposes
set dialogText to {}
repeat with aList in rgbData
set end of dialogText to item 1 of aList & " " & item 2 of aList & " " & item 3 of aList & " "
end repeat
display dialog dialogText as text buttons {"OK"} cancel button 1 default button 1
on getRGBData(theCoordinates)
set screenColors to {}
repeat with aList in theCoordinates
set {xPoint, yPoint} to {item 1 of aList, item 2 of aList}
do shell script "screencapture -R " & xPoint & "," & yPoint & ",1,1 -c"
set theData to (current application's NSPasteboard's generalPasteboard()'s dataForType:(current application's NSPasteboardTypeTIFF))
set theCIImage to (current application's CIImage's imageWithData:theData)
set thisRep to (current application's NSBitmapImageRep's alloc()'s initWithCIImage:theCIImage)
set theColor to (thisRep's colorAtX:0 y:0)
set theRed to ((theColor's redComponent()) * 255) as integer
set theGreen to ((theColor's greenComponent()) * 255) as integer
set theBlue to ((theColor's blueComponent()) * 255) as integer
set end of screenColors to {theRed, theGreen, theBlue}
end repeat
return screenColors
end getRGBData
This worked just fine.
Then I tried using the one coordinate form in 2 repeat loops as so:
use framework "AppKit"
use framework "Foundation"
use framework "QuartzCore"
use scripting additions
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 X to item i of xrow
set Y to item ic of yrow
set theCoordinates to {{X, Y}} -- x and y screen coordinates
set rgbData to getRGBData(theCoordinates)
-- a summary dialog for testing purposes
set dialogText to {}
repeat with aList in rgbData
set end of dialogText to item 1 of aList & " " & item 2 of aList & " " & item 3 of aList & " "
end repeat
display dialog dialogText as text buttons {"OK"} cancel button 1 default button 1
end repeat
end repeat
on getRGBData(theCoordinates)
set screenColors to {}
repeat with aList in theCoordinates
set {xPoint, yPoint} to {item 1 of aList, item 2 of aList}
do shell script "screencapture -R " & xPoint & "," & yPoint & ",1,1 -c"
set theData to (current application's NSPasteboard's generalPasteboard()'s dataForType:(current application's NSPasteboardTypeTIFF))
set theCIImage to (current application's CIImage's imageWithData:theData)
set thisRep to (current application's NSBitmapImageRep's alloc()'s initWithCIImage:theCIImage)
set theColor to (thisRep's colorAtX:0 Y:0)
set theRed to ((theColor's redComponent()) * 255) as integer
set theGreen to ((theColor's greenComponent()) * 255) as integer
set theBlue to ((theColor's blueComponent()) * 255) as integer
set end of screenColors to {theRed, theGreen, theBlue}
end repeat
return screenColors
end getRGBData
This returns the error at runtime:
error â-[NSBitmapImageRep colorAtX:Y:]: unrecognized selector sent to instance 0x600002664660â number -10000
It fails at the first call of handler getRGBData.
Normally I can debug plain vanilla AppleScript but I do not understand Shaneâs coding. Why does it go wrong at the second modification?
Whoops⌠I changed your first one as so:
set X to 10
set Y to 16
set theCoordinates to {{X, Y}} -- x and y screen coordinates
It failed the same way. It isnât the loop. This handler seems to fail unless the inputs are literals. What am I missing?