Getting precise text position with Swift for MacOS

Hey there! Hope you are starting the year with great joy.

My situation

I'm building a new product that is based on detecting certain text on screen in realtime. The product is only targeted for Mac and it's built with Swift

My problem

I need to get the exact position of a text element with the Apple Accessibility API but I can't figurate it out. I managed to get the AXUIElement where the text is placed but it's position is too broad and off target.

My discoveries so far

I've tried OCR but is too slow for what I'm building, so the only possible way I can think of is with the Accessibility API.

Thank you in advanced.

Getting precise text position with Swift for MacOS
 
 
Q