3

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).

daviesgeek
  • 38,901
  • 52
  • 159
  • 203

2 Answers2

1

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.

mckeed
  • 367
  • Note that while this does make this option appear enabled when looking in Preferences, it does not actually enable the behavior (at least, not on Mountain Lion). Bug, perhaps? – Lorin Hochstein Jul 31 '12 at 13:07
  • I wonder if some daemon program has to be restarted for this to take effect. Have you tried restarting the computer after running this script to see if it turns on then? – mckeed Jul 31 '12 at 20:23
  • I haven't tried, but that would make the script pretty useless if I needed to reboot! Note that just unchecking and checking the box manually works properly. – Lorin Hochstein Jul 31 '12 at 20:57
  • I was thinking about what needs to be added to the script. Maybe when you check the box manually, it both updates the setting and launches a daemon program that handles the time announcement. I'll look and see if I can figure it out when I have some time. – mckeed Aug 02 '12 at 01:28
  • 1
    Curiosity got the better of me, and I investigated and updated my answer. Please let me know if this fixes it for you. – mckeed Aug 02 '12 at 01:49
  • Yup, this worked. – Lorin Hochstein Aug 02 '12 at 21:00
  • -dict-add would be better than -dict, otherwise it clobbers the TiemAnnouncementsIntervalIdentifier setting. I wrote a separate answer that uses dict-add, but we could update this one instead and I can zap my other answer. – Lorin Hochstein Oct 22 '21 at 17:34
0

Summary

There are two steps:

  1. Change the configuration value for "Announce the time"
  2. Start/stop the speech synthesis server

The instructions below are for macOS Big Sur.

Configuration value

On macOS Big Sur, the configuration values for "Announce the time" are in the ~/Library/Preferences/com.apple.speech.synthesis.general.prefs.plist file.

You can view the current state of the file by using the defaults command:

$ defaults read ~/Library/Preferences/com.apple.speech.synthesis.general.prefs
{
    TimeAnnouncementPrefs =     {
        TimeAnnouncementsEnabled = 0;
        TimeAnnouncementsIntervalIdentifier = EveryQuarterHourInterval;
    };
}

The TimeAnnouncementPrefs.timeAnnouncementsEnabled field is a boolean that you can set to enable or disable announcements. You also need the Speech Synthesis Server daemon running, as @mckeed notes.

To enable:

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

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

To disable:

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

Note you need to use -dict-add and not dict, otherwise the TimeAnnouncementsIntervalIdentifier field will get clobbered.

Speech synthesis server

The service name of the speech synthesis server is com.apple.speech.synthesisserver

The specifier in launchctl is:

gui/$UID/com.apple.speech.synthesisserver

where $UID is your userid (e.g., 501). The UID variable should already be set for you by your shell.

Start the speech synthesis server

launchctl kickstart gui/$UID/com.apple.speech.synthesisserver

Stop the speech synthesis server

launchctl kill SIGTERM gui/$UID/com.apple.speech.synthesisserver

(For some reason, I need to run this command twice to stop the process, not sure why).

Check the status of the speech synthesis server

launchctl print gui/$UID/com.apple.speech.synthesisserver