How to Make VoiceOver to Announce ValueChanged Notification on Mac?

Hi,



I have a very simple testing code below for a custom NSView, but VoiceOver (VO) acknowledges titleChanged but ignores valueChanged notification.

I have two shortcuts for executing changeTitle and changeValue.

After making sure VO cursor is on the element, if I press the shortcut for changeTitle, VO announces the new title.

However, if I press the shortcut for changeValue, VO says nothing.

If I refocus the VO cursor manually, it reads the new value.

I can force VO to say by sending either layoutChanged or announcementRequested notification, but I'm wondering why VO ignores valueChanged notification?

The testing code is below, and thanks so much for your help!



class CustomView:NSView {


    var val = "Value"
    var title = "Title"


    override func isAccessibilityElement() -> Bool {
        return true
    }


    override func accessibilityRole() -> NSAccessibility.Role? {
        return .button
    }


    override func accessibilityTitle() -> String? {
        return title
    }


    func changeTitle() {
        title = "title \(Int.random(in:1...10))"
        NSAccessibility.post(element: self, notification: .titleChanged)
    }


    override func accessibilityValue() -> Any? {
        return val
    }


    func changeValue() {
        val = "Value \(Int.random(in:1...10))"
        NSAccessibility.post(element: self, notification: .valueChanged)
    }


}