Find text using text color (not background color)

#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

2 Likes