How do I enable "Announce the time" programmatically?
That preference seems to be stored in com.apple.speech.synthesis.general.prefs

Try this:

defaults write com.apple.speech.synthesis.general.prefs TimeAnnouncementPrefs -dict-add TimeAnnouncementsEnabled 1


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.