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?