0

I am trying to access text in active(focused) NSTextField/NSTextView (global). Is there any accessibility API that returns fieldEditor (not owned by my app)?

So far my idea is to get frontmost application (owns menubar):

NSArray<NSRunningApplication *> *runningApplications = [[NSWorkspace sharedWorkspace] runningApplications];
for (NSRunningApplication *app in runningApplications) {
    if (app.ownsMenuBar) {
        NSLog(@"App that is key front: %@", app);
    }
}

As a second step loop through tree of accessibility elements and filter the ones that have AXTextArea or AXTextField. Once I have these elements I can extract text.

PS: I don't want to listen to global key strokes/events. I need to display a window over textField

Is there any simpler way to get text than the one I have in my mind?

Marek H
  • 5,173
  • 3
  • 31
  • 42
  • See [How to insert text at cursor position of another application on Mac OSX Application (like OSK)?](https://stackoverflow.com/questions/16272717/how-to-insert-text-at-cursor-position-of-another-application-on-mac-osx-applicat/22042458) – Willeke Aug 09 '19 at 13:39
  • Possible duplicate of [How to insert text at cursor position of another application on Mac OSX Application (like OSK)?](https://stackoverflow.com/questions/16272717/how-to-insert-text-at-cursor-position-of-another-application-on-mac-osx-applicat) – Marek H Aug 09 '19 at 13:44
  • Thanks! Voted for duplicate – Marek H Aug 09 '19 at 13:44

0 Answers0