Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force NSAccessibility Voiceover to read unfocused OS X textfield?

I have a button, that when pressed, shows a "helper" window.

This window is shown, but not given keyboard focus, via orderFrontRegardless.

The window contains an NSTextView with helper text inside.

For vision-impaired users, I would like OS X's voiceover to immediately read the contents of this window's text view when it appears.

I am attempting to make VoiceOver read the text via:

NSAccessibilityPostNotification(textView, NSAccessibilityValueChangedNotification);

In my subclass of NSTextView I then override the accessibility method:

- (id)accessibilityAttributeValue:(NSString *)attribute
{
    //The notification calls this method for attributes:
    //AXRole: returns AXTextArea
    //AXSharedCharacterRange: returns range of the text view

    return [super accessibilityAttributeValue:attribute];
}

The notification causes it to query for AXRole (NSAccessibilityRoleAttribute) and AXSharedCharacterRange (NSAccessibilitySharedCharacterRangeAttribute).

The character range correctly returns the range of the text area.

However, at no point is AXValue (NSAccessibilityValueAttribute) requested. That is that I am expecting is required when wanting VoiceOver to read the textfield.

Why is the NSAccessibilityValueChangedNotification not requesting the TextView's NSAccessibilityValueAttribute? How do I make VoiceOver read the text area's text?

like image 866
pkamb Avatar asked Nov 12 '22 23:11

pkamb


1 Answers

I believe there's no way you can do it without setting the focus to the desired NSTextView.

I have found a solution using iOS that maybe can be implemented in this OSX application: VoiceOver: force an accessibility element to be selected after a screen transition

In iOS you can pass in an accessibility element when posting a UIAccessibilityLayoutChangedNotification or UIAccessibilityScreenChangedNotification as the second argument to UIAccessibilityPostNotification and VoiceOver will focus on that element.

Maybe you can use a similar approach with NSAccessibility framework with NSAccessibilityPostNotification

like image 64
ppaulojr Avatar answered Nov 15 '22 12:11

ppaulojr