# Find text using text color (not background color)

**URL:** <https://forums.eggplantsoftware.com/t/find-text-using-text-color-not-background-color/8810>\
**Category:** Eggplant Functional\
**Tags:** script, sensetalk, eggplant-functional\
**Created:** [April 17, 2024, 9:17pm UTC](https://forums.eggplantsoftware.com/t/find-text-using-text-color-not-background-color/8810 "2024-04-17T21:17:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![scsvel](https://forums.eggplantsoftware.com/user_avatar/forums.eggplantsoftware.com/scsvel/32/316_2.png) [@scsvel](https://forums.eggplantsoftware.com/u/scsvel)\
**Post date:** [April 17, 2024, 9:17pm UTC](https://forums.eggplantsoftware.com/t/find-text-using-text-color-not-background-color/8810/1 "2024-04-17T21:17:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PKenMer](https://forums.eggplantsoftware.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@PKenMer](https://forums.eggplantsoftware.com/u/PKenMer)\
**Post date:** [April 18, 2024, 8:18am UTC](https://forums.eggplantsoftware.com/t/find-text-using-text-color-not-background-color/8810/2 "2024-04-18T08:18:03Z")

</div>

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.

```auto
// 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

```

---

<div class="post-metadata">

**Author:** ![scsvel](https://forums.eggplantsoftware.com/user_avatar/forums.eggplantsoftware.com/scsvel/32/316_2.png) [@scsvel](https://forums.eggplantsoftware.com/u/scsvel)\
**Post date:** [April 18, 2024, 1:58pm UTC](https://forums.eggplantsoftware.com/t/find-text-using-text-color-not-background-color/8810/3 "2024-04-18T13:58:55Z")

</div>

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.  
 ![image](https://forums.eggplantsoftware.com/uploads/default/original/1X/1191e7ce0030909bc7fdadeab6d7f2974762a962.png)

---

<div class="post-metadata">

**Author:** ![shenpeng](https://forums.eggplantsoftware.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@shenpeng](https://forums.eggplantsoftware.com/u/shenpeng)\
**Post date:** [April 19, 2024, 2:40am UTC](https://forums.eggplantsoftware.com/t/find-text-using-text-color-not-background-color/8810/4 "2024-04-19T02:40:09Z")

</div>

You can capture two images for a link or button disabled and enabled.

---

<div class="post-metadata">

**Author:** ![shenpeng](https://forums.eggplantsoftware.com/letter_avatar_proxy/v4/letter/s/b77776/32.png) [@shenpeng](https://forums.eggplantsoftware.com/u/shenpeng)\
**Post date:** [April 19, 2024, 2:43am UTC](https://forums.eggplantsoftware.com/t/find-text-using-text-color-not-background-color/8810/5 "2024-04-19T02:43:29Z")

</div>

#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

---

<div class="post-metadata">

**Author:** ![scsvel](https://forums.eggplantsoftware.com/user_avatar/forums.eggplantsoftware.com/scsvel/32/316_2.png) [@scsvel](https://forums.eggplantsoftware.com/u/scsvel)\
**Post date:** [May 29, 2024, 5:37pm UTC](https://forums.eggplantsoftware.com/t/find-text-using-text-color-not-background-color/8810/6 "2024-05-29T17:37:03Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![DaveHester](https://forums.eggplantsoftware.com/user_avatar/forums.eggplantsoftware.com/davehester/32/104_2.png) [@DaveHester](https://forums.eggplantsoftware.com/u/DaveHester)\
**Post date:** [May 31, 2024, 4:32pm UTC](https://forums.eggplantsoftware.com/t/find-text-using-text-color-not-background-color/8810/7 "2024-05-31T16:32:50Z")

</div>

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

 ![image](https://forums.eggplantsoftware.com/uploads/default/original/1X/dc7dae16c22d9d707303568aa4492e543a162cc4.png)
