Insert rich text using accessibility API in Cocoa?

I am trying to insert some formatted text in Cocoa using the accessibility API. This is what I did:

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' 

I always get the error kAXErrorIllegalArgument (-25201) . If I try to insert plain text, then it works fine.

So, does anyone know how to insert formatted text using the accessibility API?

+5
source share
1 answer

I do not think you can set a description, value or title for the attribute string. Perhaps you can assign a string with AXUIElementCopyParameterizedAttributeValue , but not AXUIElementSetParameterizedAttributeValue .

0
source

Source: https://habr.com/ru/post/1242873/


All Articles