# Clever OCR pipe-dream

**URL:** <https://forums.eggplantsoftware.com/t/clever-ocr-pipe-dream/8652>\
**Category:** Eggplant Functional\
**Tags:** ocr\
**Created:** [November 6, 2023, 6:43pm UTC](https://forums.eggplantsoftware.com/t/clever-ocr-pipe-dream/8652 "2023-11-06T18:43:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LoganC](https://forums.eggplantsoftware.com/user_avatar/forums.eggplantsoftware.com/loganc/32/123_2.png) [@LoganC](https://forums.eggplantsoftware.com/u/LoganC)\
**Post date:** [November 6, 2023, 6:43pm UTC](https://forums.eggplantsoftware.com/t/clever-ocr-pipe-dream/8652/1 "2023-11-06T18:43:27Z")

</div>

Does anyone know a clever way to make OCR do the following:

I have a list of 10 links. I want to click on 5 of them. I want to do this with a repeat loop that will repeat for each item of ListOfThingsToClick.

set ListOfThingsToClick to [  
“Apple”,  
“Red Apple”,  
“Banana”,  
“Orange”,  
“Frisbee”  
]

My links look like this:  
Green Apple  
Apple  
Red Apple  
Banana  
Orange  
Frisbee  
Cat  
House  
Pirate  
Dog

The obvious issue is that if I tell it to repeat for each item ListOfThingsToClick its going to find “Apple” in three places. And if I tell it to just click the first item of everyimagelocation I’m going to get “Green Apple” twice. Even if I set “first item” to a counter, I still won’t get the clicks I want.

Best I can think of is to tell it to OCR the stuff ‘nearby’ and make sure there are no other characters in the vicinity. But that’s tricky of course because there will generally be other artifacts on any given page. It would also be time-consuming.

Let’s assume I don’t want to take image captures of my links.

I feel like someone probably knows a clever way to make OCR ‘care’ about what’s around it, but maybe I’m expecting too much. Just thought I’d check. I’ll probably have to convert everything to images and deal with the outliers.

Thanks,

Logan Craig  
IBM | Senior Software QA Engineer  
Digital Transformation Center (DTC) | OIT  
C: 480.516.8322

---

<div class="post-metadata">

**Author:** ![Karsten](https://forums.eggplantsoftware.com/letter_avatar_proxy/v4/letter/k/e47c2d/32.png) [@Karsten](https://forums.eggplantsoftware.com/u/Karsten)\
**Post date:** [November 7, 2023, 10:16am UTC](https://forums.eggplantsoftware.com/t/clever-ocr-pipe-dream/8652/2 "2023-11-07T10:16:28Z")

</div>

Hey Logan,

Sensetalk Pattern for Text is the answer:

```auto
repeat for each item in ListOfThingsToClick
	put "Word to find:" && it
	set mypattern to <not preceded by (1 to 2 characters) , it, not followed by (many characters) >
	put imagelocation(text:mypattern)
end repeat

```

How to “read” it: Find the word `apple` this has _not_ any one or two characters before and any number of characters behind.

[Here is another](https://forums.eggplantsoftware.com/t/incorrect-text-reading-from-vnc/8653/2) example for Sensetalk pattern for an unknown version number on screen.

[Here is the docu](https://docs.eggplantsoftware.com/studio/stk-pattern-language/#pattern) for sensetalk patterns. Its essentially a more readable regular expression.

```auto
put Mypattern // prints the regular expression (?<!(?:.{1,2}?))Apple(?!(?:.+))

```

Sensetalk pattern for text searches are powerful. Just takes some training to master them. Trust me its worth the effort.

Cheers,  
Karsten

---

<div class="post-metadata">

**Author:** ![LoganC](https://forums.eggplantsoftware.com/user_avatar/forums.eggplantsoftware.com/loganc/32/123_2.png) [@LoganC](https://forums.eggplantsoftware.com/u/LoganC)\
**Post date:** [November 7, 2023, 3:31pm UTC](https://forums.eggplantsoftware.com/t/clever-ocr-pipe-dream/8652/3 "2023-11-07T15:31:47Z")

</div>

Thanks! This looks like exactly the sort of thing I was hoping for.  
Logan
