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

时间:2016-02-12 13:45:27

标签: objective-c cocoa accessibility 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'

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

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

1 个答案:

答案 0 :(得分:0)

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