I’m not sure if this will help you, but if all you are looking to do is retrieve the color values at your exact mouse coordinates, this alternate solution may be an option for you.
This following AppleScript code added as an AppleScript action to a new Automator Quick Action, will allow you to retrieve color values at your exact mouse coordinates, without the need to call on System Events or any Color Picker GUI.

I saved my version in Automator as “Eyedropper At Mouse Location.workflow”. I then assigned it the keyboard shortcut ⇧⌃P in System Preferences/Keyboard/Shortcuts/Services. Now, pressing the keyboard shortcut ⇧⌃P while in any application, will retrieve the RGB color values at my exact mouse location.
—————————————————————————————————————-
This code requires the third-party utility, Cliclick.
“Cliclick” is short for “Command-Line Interface Click”. It is a a tiny shell/Terminal application that will emulate mouse clicks or series of mouse clicks (including doubleclicks and control-clicks) at arbitrary screen coordinates. Moreover, it lets you move the mouse, get the current mouse coordinates, press modifier keys etc.
It's free to download but it's donationware, and is easy to install.
On my system I have. cliclick
in the following directory: /usr/local/bin/
. Because of this location, in my AppleScript code and in Terminal app, I need to use the full path to cliclick
to call the command. For example: do shell script "/usr/local/bin/cliclick rc:."
In AppleScript is telling cliclick
to right-click.
—————————————————————————————————————-
I’m not quite sure what you intend to do with the color values retrieved so I created three different variables… rgbColors
(R,G,B values as integers as record), theColors
(R,G,B values as text as list), and theColorsAsText
(R,G,B values as 1 long string)
property rgbColors : {R:0, G:0, B:0}
set theColors to words of ¬
((do shell script "/usr/local/bin/cliclick cp:.") as string) as list
set theColorsAsText to (("Red:" & theColors's item 1) & " Green:" & ¬
theColors's item 2) & " Blue:" & theColors's item 3
(* Not Necessary But This Will Store The Values As A Record Making It ¬
Easier To Call On Or Manipulate, If Need Be, In Other Parts Of The Script*)
set {rgbColors's R, rgbColors's G, rgbColors's B} to ¬
{theColors's item 1 as integer, theColors's item 2 as integer, ¬
theColors's item 3 as integer}
activate
display dialog theColorsAsText buttons {"OK"} ¬
default button "OK" giving up after 4