Ninad Vartak
Ninad Vartak

Reputation: 31

How to detect VoiceOver status changes in Mac app

I have a Mac application.
I want to enable / disable some app functionality depending upon if VoiceOver has been enabled or not.

I know that I can detect if VoiceOver has been enabled / disabled using [[NSWorkspace sharedWorkspace] isVoiceOverEnabled].

Apart from this, I want to register for a notification to detect the changes in VoiceOver status (enabled / disabled).
I found that, this can be achieved in iOS by registering to UIAccessibilityVoiceOverStatusDidChangeNotification notification.
But, I did not find similar notification for macOS.

Can anyone please tell me how can I achieve this in macOS.

Upvotes: 1

Views: 233

Answers (1)

massimobio
massimobio

Reputation: 818

You can use KVO to observe changes to NSWorkspace.shared.isVoiceOverEnabled

I used closure based KVO in Swift and added an observation property to my class:

private var voiceOverObservation: NSKeyValueObservation?

and in init:

voiceOverObservation = NSWorkspace.shared.observe(\.isVoiceOverEnabled) { _, _ in
    print(NSWorkspace.shared.isVoiceOverEnabled)
}

Upvotes: 2

Related Questions