3

I like Time Announce during the day while I am working. But I want it off when I am sleeping.

Apple's Do Not Disturb function will mute notifications and sounds associated with them, but it has no effect on Time Announce.

Elsewhere on this site there is an old answer from a number of years ago that offered this script:

do shell script "defaults write ./com.apple.speech.synthesis.general.prefs TimeAnnouncementPrefs -dict TimeAnnouncementsEnabled -bool YES"

Similar script to turn it off.

Another answer can be found here, but goes back to the days of Mountain Lion:

How do I enable "Announce the time" programmatically?

I am new here and a rank beginner to Aapplescript. I do not have the privilege of commenting yet to seek clarification from the authors of the answers presented.

These scripts do not work on Mac OS X High Sierra (10.13). While the first script will compile, when run nothing happens. The script from the page referenced won't even compile. Syntax error about an unknown token after an identifer.

In addition, making a change manually to this preference in settings requires my password to unlock. Can AppleScript or Automator deal with that too?

2
  • It should work, try changing "./" in the script to "~/Library/Preferences/" and give that a try.
    – Kyle
    Commented Oct 22, 2017 at 17:51
  • Nope. The result is "". Tried it after validating to unlock the preference. Can AppleScript get around the validation routines that require my passcode to unlock every preference, every time.
    – NormG
    Commented Oct 22, 2017 at 17:56

2 Answers 2

1

UPDATE: This works for me using the latest version of High Sierra.

This version will "turn on" "Announce the time:" if not already enabled

property thePassword : "yourpassword"

tell application "System Preferences"
    reveal anchor "ClockPref" of pane id "com.apple.preference.datetime"
    tell application "System Events"
        delay 0.5
        my enterPassword()
        set theValue to get value of checkbox "Announce the time:" of tab group 1 of window "Date & Time" of application process "System Preferences"
        if theValue is 0 then
            click checkbox "Announce the time:" of tab group 1 of window "Date & Time" of application process "System Preferences"
        end if
    end tell
    delay 1
    quit
end tell


on enterPassword()
    tell application "System Events"
        try
            click button "Click the lock to make changes." of window "Date & Time" of application process "System Preferences"
        end try
        delay 1
        --activate
        set value of text field "Enter password" of sheet 1 of window "Date & Time" of application process "System Preferences" to thePassword
        delay 1
        click UI element "Unlock" of sheet 1 of window "Date & Time" of application process "System Preferences"
    end tell
end enterPassword

This version will "turn off" "Announce the time:" if already enabled

property thePassword : "yourpassword"

tell application "System Preferences"
    reveal anchor "ClockPref" of pane id "com.apple.preference.datetime"
    tell application "System Events"
        delay 0.5
        my enterPassword()
        set theValue to get value of checkbox "Announce the time:" of tab group 1 of window "Date & Time" of application process "System Preferences"
        if theValue is 1 then
            click checkbox "Announce the time:" of tab group 1 of window "Date & Time" of application process "System Preferences"
        end if
    end tell
    delay 1
    quit
end tell


on enterPassword()
    tell application "System Events"
        try
            click button "Click the lock to make changes." of window "Date & Time" of application process "System Preferences"
        end try
        delay 1
        --activate
        set value of text field "Enter password" of sheet 1 of window "Date & Time" of application process "System Preferences" to thePassword
        delay 1
        click UI element "Unlock" of sheet 1 of window "Date & Time" of application process "System Preferences"
    end tell
end enterPassword

enter image description here


I could have set the script to perform the action of clicking checkbox "Announce the time:" if it was not enabled already… with conditional statements of setting enabled or disabled of that checkbox during certain times. I figured, for now, it would just be easier to save two different versions of the script. One version for turning on checkbox "Announce the time:" and one version for turning off checkbox "Announce the time:”. In ScriptEditor, just saved each version of the script as applications. From there just simply open Calendar.app and create two new calender events. one event for enabling checkbox "Announce the time:" at whatever time you choose. And another for disabling.. Once you create the event, just create a custom alert and select the option of open file then choose your script which you saved as an app.

enter image description here

4
  • Sorry to say the script fails. It pops a Script Error that says "System Events got an error. Can't set Application Process 'SecurityAgent' to 'myactualpassword' " At the same time, System Preferences Icon bounces in the dock to tell me System Preferences is trying to unlock the Date and Time Preferences and asking me to manually allow that to happen by entering my password. So in effect, it wants my password manually entered in System Preferences in order to allow the script to enter my password in Date & Time preferences.
    – NormG
    Commented Oct 23, 2017 at 16:33
  • But I think your script is very close, just need to solve the fact that Apple wants the password entered twice in two places. Also, of course, I was prompted to give Script Editor the ability to control my computer under Privacy Accessibility preference.
    – NormG
    Commented Oct 23, 2017 at 16:37
  • I updated the code in the answer. It now works with High Sierra only
    – wch1zpink
    Commented Oct 24, 2017 at 4:05
  • 1
    You got it! Works perfectly. Apple should have built this into the announce the time function. It would have been a long learning curve for me to figure this out. So Thank You!
    – NormG
    Commented Oct 24, 2017 at 4:34
0

Easy Fix Via Terminal, If That's Cool

If you're still having this issue, it's annoying, but here's a simple way as of Big Sur, in the terminal:

Turn "Announce the Time" On

plutil -replace TimeAnnouncementPrefs.TimeAnnouncementsEnabled -bool YES /Users/macbook/Library/Preferences/com.apple.speech.synthesis.general.prefs.plist; defaults read com.apple.speech.synthesis.general.prefs.plist;

Turn "Announce the Time" Off

plutil -replace TimeAnnouncementPrefs.TimeAnnouncementsEnabled -bool NO ~/Library/Preferences/com.apple.speech.synthesis.general.prefs.plist; defaults read com.apple.speech.synthesis.general.prefs.plist;

Scheduling

Keep it simple. Use crontab.

#m      h       dom     mon     dow     command
5       23      *       *       *       plutil -repla...
5       7       *       *       *       plutil -repla...

Stating obvious, use the full line (on a single line) vs the ellipses... If you're not familiar with crontab, you can cheat and just use this site (or many others) to generate the full line for you.

Explanation

The first line is an edit command using plutil in the terminal to edit the preferences in com.apple.speech.synthesis.general.prefs.plist.

You can use plutil to view the preferences in the terminal as follows:

plutil -p ~/Library/Preferences/com.apple.speech.synthesis.general.prefs.plist

...which in Big Sur, shows...

{
  "TimeAnnouncementPrefs" => {
    "TimeAnnouncementsEnabled" => 0
    "TimeAnnouncementsIntervalIdentifier" => "EveryHourInterval"
    "TimeAnnouncementsPhraseIdentifier" => "ShortTime"
    "TimeAnnouncementsVoiceSettings" => {
      "CustomVolume" => 0.1148504
    }
  }
}

The TimeAnnouncementPrefs.TimeAnnouncementsEnabled is the BOOL switch we're toggling on and off with the -bool YES or -bool NO. I'm sure the other settings do something, but honestly, not enough time in the day. I'm simple... on switch/off switch.

The second line forces the Mac to reload that pref so you don't need to kill any apps or reboot. If you don't run the second command, the change won't take effect until you reboot or force kill it. (For the CLI folks, it's the Mac equivalent of source ~/.bash_profile when changing PATHs or aliases or whatnot.

Note if you have the System Preferences -> Dock & Menu Bar -> Clock open in prefs when you do this, the UI will NOT reload to reflect the changes. Close Systems Preferences entirely (vs. arrow back) and reopen (don't save), and you'll see the change reflected. If you don't, the pref is still changed but you run the risk of saving over it.

Not the answer you're looking for? Browse other questions tagged .