开发者

Enable "Announce the time" with Applescript

How do I enable the "Announce the t开发者_JS百科ime" option in the Date & Time System Preference using Applescript?


You can do this via a terminal command: defaults write

I managed to dig out the preference file that's being written to when you toggle this setting: ~/Library/Preferences/com.apple.speech.synthesis.general.prefs.plist. Note that this file may not exist on your computer; it's only created if you've toggled the "Announce the time" checkbox in System Prefs.

The key you're changing the value for is TimeAnnouncementsEnabled, which takes a boolean value of YES to turn on the announcements and NO for off. This key is inside of the dictionary TimeAnnouncementPrefs which houses the other settings related to the voice announcements. The terminal command to turn on the time announcements is:

defaults write com.apple.speech.synthesis.general.prefs TimeAnnouncementPrefs -dict TimeAnnouncementsEnabled -bool YES

To use this in an AppleScript simply do the following (to run a terminal command from AppleScript):

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

That should do it. The other preference keys (voice, custom rate and custom volume) will be reset to their defaults if you use the command as above. If you want to set them to non-default values you'll have to explicitly set them along with the above key value. However, since there are some nested dictionaries you'd probably need to look at using plistbuddy (which isn't installed by default AFAIK). However, if you only want to set the announcement on/off option, don't worry about it. This will set you up!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜