Is there any property to use with Click or Find kind of commands to find out if a particular text is of some color?
I need to find if a link or button is disabled or not, and take actions further. Both the active and disabled links will have same background color but different foreground color. Not sure if the contrast and contrast-color would help here. Appreciate any help.
Hi, I would use contrast colour for this. Pick out the disabled text colour and the enabled text colour and add a search rectangle around the button.
You can add if statements around these too depending on the logic you desire.
// Expecting button to be disabled
set buttonText to ReadText([840,176,1130,214], contrast:"On", contrastColor:"#FFFFFF", contrastTolerance:"45")
Log buttonText
// Expecting button to be enabled
set buttonText to ReadText([840,176,1130,214], contrast:"On", contrastColor:"#FC2B28", contrastTolerance:"45")
Log buttonText
Hello - I have already tried with this but no luck. It is finding the text irrespective of color that I am passing or no idea only if it is considering background color for contrast.
Also, tried to check the color using ColorAtLocation, and it gives same color for both enabled text and disabled text locations.
Attached the image for ref.
You can capture two images for a link or button disabled and enabled.
#getTextColor.script
params searchArea
set the searchRectangle to searchArea # for debug
repeat with y = searchArea.Top to searchArea.Bottom
repeat with x = searchArea.Left to searchArea.Right
set dotColor to ColorAtLocation(x, y)
log βcolor at [β&x&β, β&y&β]=(β&dotColor&β)β # for debug
set RGB to split(dotColor, β,β)
set redPart to item 1 of RGB
set greenPart to item 2 of RGB
set bluePart to item 3 of RGB
if (redPart<128 and greenPart>201 and bluePart<128) or \
(greenPart>210 and redPart + bluePart<180)
return "green"
else if redPart>201 and greenPart<128 and bluePart<128
return "red"
else if (redPart = 0) and \
(greenPart between 113 and 126) and \
(bluePart between 147 and 159)
return "blue"
else if (redPart between 125 and 130) and \
(greenPart between 74 and 76) and \
(bluePart between 46 and 50)
return "yellow"
end if
end repeat
end repeat
set the searchRectangle to empty # for debug
@shenpeng Thanks for the idea, this helps me to get my logic. Appreciate the help.
Still, Itβs better to have a eggplant command to get text color rather using this repeat loop for each/every pixel in the area.
Hi Shan,
Part of the issue with text color is demonstrated in the attached image. Both text images come from the very same machine but with two different ClearType settings. In both cases, the text color was #000000, but the number of individual pixels that are #000000 are only a fraction of the total number of pixels. Please feel free to reach out to your TCSM to submit a feature request for TextColor as a function, but please be aware that the solution is far from straightforward.
Dave