The arrival of Mac OS X Lion (10.7) several months ago marked yet another milestone for Apple’s desktop operating system. It ushered in several significant improvements such as iCloud, versions, revamped apps, and of particular interest to myself and the rest of the visually impaired community, some accessibility enhancements. After some much needed hardware upgrades to my aging Mac Pro, I installed the new OS only to come to a disturbing realization, a feature that I rely upon perhaps more than any other, was not working the way I had come to expect.
Why, oh why, had this feature that I had come to depend on so heavily, now suddenly become 50% useless? I scoured the internet for answers and finally came across the explanation in a somewhat unlikely place. This Firefox bug and subsequent comments describe, in very drawn out terms, a distinct change in the way “speak selected text” worked in 10.6 and earlier, and how it now works in 10.7. It turns out that in 10.6, there was a “Speech Service” agent, always running, and waiting for the configured hotkey to be activated. Upon activation, it would, **hand wave**, trigger a copy of currently selected text, and then feed the contents of the clipboard into the speech synthesis engine. In 10.7, it seems as though Apple have “upgraded” this process to instead capture the target text via well-known accessibility APIs. This method is arguably less “hacky” and more “correct”, but is much less likely to work across every application. While copy+paste works in pretty much every app, an unfortunately low percentage of apps are thorough about enabling accessibility. And thus, the “old” method for enabling this feature seems much preferable.
Naturally, my next thought was “hey! I’m a compitent developer and stand-up human being, so why don’t I try to recreate the 10.6 method as a headless Cocoa app”, and so I did. One coffee-enhanced Friday night later and “SpeakCopy” was born. I won’t go into code-level details on what this app does, but a technical overview follows:
- Registers a hotkey listener for “option+control+f” (hardcoded for now).
- On hotkey press, uses keyboard events to send a “command+c” to trigger a copy event.
- Fetches the text from NSPasteBoard and feeds it directly into NSSpeechSynthesizer.
The app uses the speech defaults you configure in the “Speech” pane of System Preferences and has very similar behavior to the 10.6 feature.
If you’d like to use SpeakCopy, you can download the app here. Once you double-click to run it, it will start listening for the hotkey. You can also add it as a Login Item by going to the User Accounts pane in System Preferences, this will make it start automatically every time you reboot your Mac, which is very convenient.
The full source code is also available in this GitHub repository. Feel free to check it out and improve it. Hopefully Apple will address the shortcomings that this project remedies, but if it doesn’t, I will continue to maintain it.