I'm trying to insert some formatted text in Cocoa using accessibility API. This is what I've done:
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'
The error I always get is kAXErrorIllegalArgument (-25201)
. If I try to insert non-formatted text then it works fine.
So, does anyone know how to insert a formatted text using accessibility API?