在Cocoa中使用辅助功能API插入格式化文本?

ash*_*lal 5 cocoa accessibility objective-c nsattributedstring

我正在尝试使用辅助功能API在Cocoa中插入一些格式化文本.这就是我所做的:

NSFont *font = [NSFont fontWithName:@"Arial" size:14.0];
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"hello, world" attributes:attrsDictionary];
AXError error = AXUIElementSetAttributeValue(element, kAXValueDescriptionAttribute, attrString);
// element is an instance of 'AXUIElementRef' with role 'AXTextArea'
Run Code Online (Sandbox Code Playgroud)

我总是得到的错误是kAXErrorIllegalArgument (-25201).如果我尝试插入非格式化的文本,那么它工作正常.

那么,有没有人知道如何使用辅助功能API插入格式化文本?

Wil*_*eke 0

我认为您不能将描述、值或标题设置为属性字符串。也许您可以使用 获得属性字符串,AXUIElementCopyParameterizedAttributeValue但没有AXUIElementSetParameterizedAttributeValue.