3

Hey StackOVerflow community!

I'm building some macOS app that should "read" and highlight some specific words on the screen. Only if they are inside NSTextView or NSTextField.

While using Accessibility API I can get the text out of these UI elements as well as I can add a transparent NSWindow on top of the target app where I can then draw highlighting. The problem is that I don't know how to find coordinates of some specific words so that I can draw my highlighting.

To give you some real-world example here is the screenshot of the Grammarly app. Whenever it finds a typo - it places NSWindow on top of the text area where they draw bubbles. I'm building a very similar app.enter image description here

On the picture, I provided you can see that "Hello" as well as "wold" is highlighted. "Hello" also has a Hover view that gets visible whenever the mouse is on top of this word. So to my understanding, they are using some Accessibility API to get coordinates. The question is which API?

Thanks in advance for any support!

Sapozhnik Ivan
  • 235
  • 3
  • 7
  • 1
    [boundsForRange](https://developer.apple.com/documentation/appkit/nsaccessibility/parameterizedattribute/1526412-boundsforrange/) sounds like what you're looking for. – Willeke Feb 02 '22 at 21:04
  • Hey @Willeke and thanks for your answer. I've been looking at this property but it looks like it just takes one parameter which is Range. In the picture above we have two words - Hello and wold, which means that we would need to get array of ranges and then call this property N times (for every range that we found), right? – Sapozhnik Ivan Feb 03 '22 at 09:58
  • Yes, boundsForRange does one range. – Willeke Feb 03 '22 at 12:20

0 Answers0