macOS accessibility API on WebKit applications with AXTextMarker

后端 未结 3 1304
没有蜡笔的小新
没有蜡笔的小新 2021-01-16 07:18

I need to access data from webkit applications such as Safari, Mail and maybe others. I can see in the Accessibility Inspector there is :AXTextMarker

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-16 07:47

    Tips and tricks:

    Ask focussedElement for its supported attributes. Use the functions:

    AXError AXUIElementCopyAttributeNames(AXUIElementRef element, CFArrayRef  _Nullable *names);
    

    Returns a list of all the attributes supported by the specified accessibility object.

    and

    AXError AXUIElementCopyParameterizedAttributeNames(AXUIElementRef element, CFArrayRef  _Nullable *names);
    

    Returns a list of all the parameterized attributes supported by the specified accessibility object.

    Most undocumented attributes are self explanatory.

    For example get the selected text as attributed string:

    CFTypeRef markerRange = NULL;
    AXError error = AXUIElementCopyAttributeValue(focussedElement, (CFStringRef)@"AXSelectedTextMarkerRange", &markerRange);
    CFTypeRef result = NULL;
    error = AXUIElementCopyParameterizedAttributeValue(focussedElement, (CFStringRef)@"AXAttributedStringForTextMarkerRange", markerRange, &result);
    

提交回复
热议问题