I’m trying to figure out how to read the contents of an AXTextArea so that each string in the AXTextArea is put into an NSArray using Accessibility.
what do you mean by “each string in the AXTextArea”? AXTextArea is in principle a single huge string (as represented by the AXValue attribute), any division of it into logical substrings is kind of artificial and based on your choice of criteria (logic) how you want to do this subdivision.
If you want to divide the string by lines, then these attributes should be sufficient to iterate over them:
- AXNumberOfCharacters (attribute)
- AXRangeForLine (parameterized attribute)
- AXStringForRange (parameterized attribute)
Beware that these are *visual* lines, i.e. if you have a paragraph (where paragraph is defined as longest block of text containing a single newline at the end) which does not fit in one line (i.e. it has to be soft-wrapped at the trailing edge of the text view), then each of these soft-wrapped lines will be reported as a separate line by AXRangeForLine. Last line of paragraphs should have a newline character reported as their last character, though you cannot always rely on that (some frameworks might have a bug where they exclude the newline from the last line in paragraph).
Does anyone know of some sample code or pointers to docs available?
Accessibibility APIs in ApplicationServices, functions, types and constants beginning with the AX prefix, they live in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/ApplicationServices.framework/Frameworks/HIServices.framework/Headers/AX*.h
Based on the names there you should be able to find them also in the online docs :-)
But as always, headers sometimes contain interesting comments should you feel interested in that.