Mac: How to detect if a text field is focused system-wide manner?

Grammarly can detect if a text field is focused on any apps including note, safari and mail on Mac.
It can access the text and get position of that text field to place their widget right beside it.

How can I achieve this? I think it's related to Accessibility Focus State?

Hello. These forums are focused on topics related to the Swift programming language itself, not on application related questions. :slight_smile:

I have tagged SwiftUI