使用AXTextMarker的WebKit应用程序上的macOS可访问性API [英] macOS accessibility API on WebKit applications with AXTextMarker
问题描述
我需要从Safari,Mail等Webkit应用程序访问数据,也许还要从其他应用程序访问数据.我可以在Accessibility Inspector
中看到:AXTextMarker
和AXTextMarkerForRange
.
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
and AXTextMarkerForRange
.
我尝试了获取此信息的常用方法:
I tried the usual way to get this info :
AXUIElementRef systemWideElement = AXUIElementCreateSystemWide(); //creating system wide element
AXUIElementRef focussedElement = NULL;
AXError error = AXUIElementCopyAttributeValue(systemWideElement, kAXFocusedUIElementAttribute, (CFTypeRef *)&focussedElement); //Copy the focused
if (error != kAXErrorSuccess){
NSLog(@"Could not get focused element");
}else{
AXValueRef marker = NULL;
AXError getTextValueError = AXUIElementCopyAttributeValue(focussedElement, kAXMarkerUIElementsAttribute , (CFTypeRef *)&marker);
}
kAXMarkerUIElementsAttribute
是我用Marker可以看到的唯一东西,但是每次都为空.
kAXMarkerUIElementsAttribute
is the only thing I can see with Marker but everything is empty each time.
我猜出于安全原因,我无法访问它们?有什么可能的办法.我正在为阅读困难的人开发一个应用程序,它确实可以提供帮助.
I guess for security reasons, I cannot access them? Is there any way possible. I am developing an app for people with difficulties reading and it could really help.
谢谢
推荐答案
提示和技巧:
向focussedElement
询问其支持的属性.使用功能:
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.
和
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);
这篇关于使用AXTextMarker的WebKit应用程序上的macOS可访问性API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!