How do I enable "Announce the time" programmatically?

The "Date & Time" System Preferences pane has an option to "Announce the time". I'd like to be able to turn on this preference option by invoking a shell script. Is this possible?

(It's fine if this involves invoking a separate script written in Applescript).


That preference seems to be stored in com.apple.speech.synthesis.general.prefs

Try this:

defaults write ~/Library/Preferences/com.apple.speech.synthesis.general.prefs TimeAnnouncementPrefs -dict TimeAnnouncementsEnabled -bool YES

or 0 at the end to turn it off. See man defaults for more info.

Edit: Another thing that the shell script should do: if you haven't enabled this preference or another speech synthesis behavior since startup, you'll also need to launch the Speech Synthesis Server daemon:

open /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/SpeechSynthesis.framework/Versions/A/SpeechSynthesisServer.app

otherwise, the option will show up as checked in System Preferences, but nothing will actually read the option when it is time to speak the time.