Name Last Update
VoiceoverDetectionSpike Loading commit data...
VoiceoverDetectionSpike.xcodeproj Loading commit data...
VoiceoverDetectionSpikeTests Loading commit data...
readme.md Loading commit data...

VoiceOver Status Detection

No longer working :(

Apple seems to have broken this (testing with Xcode 8.2.1 and Swift 3 under macOS Sierra 10.12.2) as accessibilitySetValue(_:forAttribute:) is no longer getting called. This is a shame as they have not implemented an NSAccessibilityIsVoiceOverRunning() method of their own (even though there is a UIAccessibilityIsVoiceOverRunning() on iPhone/iPad and WKAccessibilityIsVoiceOverRunning() on Apple Watch).


Enables VoiceOver status to be queried and observed on OS X.

Usage

import Cocoa

class ViewController: NSViewController
{
    @IBOutlet weak var voiceOverStatusLabel: NSTextField!
    @IBOutlet weak var voiceOverIconImageView: NSImageView!

    var voiceOverObserver:NotificationObserver!

    override func viewDidAppear()
    {
        super.viewDidAppear()

        voiceOverObserver = handle(NSAccessibilityVoiceOverStatusChanged) { notification in

            let voiceOverIsRunning = NSAccessibilityIsVoiceOverRunning()
            var statusMessage = "VoiceOver is "
            statusMessage += voiceOverIsRunning ? "on." : "off."

            self.voiceOverIconImageView.setAccessibilityLabel(statusMessage)
            self.voiceOverStatusLabel.stringValue = statusMessage
            self.voiceOverIconImageView.enabled = voiceOverIsRunning

        }
    }

    override func viewWillDisappear()
    {
        voiceOverObserver.remove()
        super.viewWillDisappear()
    }
}

(See NSNotificationCenterExtensions for the custom notification observing code. Yes, that’s an emoji in there… deal with it.) :)

Instructions

Open VoiceoverDetectionSpike.xcodeproj in Xcode and drag VoiceOverStatus.swift into your own project.

Then:

  • For updates, listen to the NSAccessibilityVoiceOverStatusChanged notification. The userInfo dictionary will have the current status in the IsVoiceOverRunning key.

  • You can also call the NSAccessibilityIsVoiceOverRunning() function to get the current status of VoiceOver.

(These mirror the UIAccessibilityVoiceOverStatusChanged notification and UIAccessibilityIsVoiceOverRunning() function on iOS.)

Demonstration

Run the project for a demonstration.

ViewController.swift is where the magic happens.

Credits

Copyright © 2015 Aral Balkan. Released with by Ind.ie under the MIT License.