Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Speak the time on the hour via Terminal UNIX
Some may be familiar the say command, where you simply open the terminal and type say (something) and your mac will speak. This is especially fun when you are logged in remotely via ssh, and someone is close to your mac at home.

Anyhow, by combining the say and date commands, you can then set up a cron job that will allow your Mac to speak the time at any interval you choose. I'm not sure if there are utilities out there that can do this, but this is certainly a good way learn how to use some of the Unix goodness in OS X.

[robg adds: You can set up a voice announcement on the Clock tab of the Date & Time System Preferences panel -- at least on the hour, half-hour, or quarter hour. Read on, however, if you're new to the Unix side of OS X and you're interested in learning a bit more about it. This solution also has the advantage of running for all users, not just for the logged-in user.]

Here's what to do:
  1. Open Terminal, in Applications/Utilities, and navigate to a directory where you want to store the script. For example, type cd /Users/username/scripts.
  2. Type sudo -s, press Return, and enter your admin password when prompted. You're now logged in (inside Terminal) as the root user.
  3. Type nano time.sh (or you could use another text editor if you've done this before). You'll get a screen where you'll type in the info for your shell script.
  4. Type say it is now `date +%I`, oh clock. Be sure to use the ` symbol and not the ' symbol -- the correct one is found on the same key as the tilde (~). Explanation: `date +%I` returns the value of the current hour in non-military format. You can use man date to see different outputs options. Using oh clock seems to be the best way to get the computer to say it correctly -- say cannot use contractions.
  5. Press Control-X, then Y, then press Enter to save your file.
  6. Now you have to make the script executable. Type chmod +x time.sh and press Return.
Test the script by typing ./time.sh and pressing Return. You should hear a male voice saying "It is now nn O'clock." Now we want to make a cron job to execute the script at specific intervals, like every hour. This is also very easy.
  1. Type crontab -e at the Terminal prompt. You'll get a blank screen, and you are using the vi editor by default.
  2. Press the letter i -- this will put you into 'insert' mode. You should see the word insert at the bottom of the screen.
  3. To make this script run every hour, on the hour, enter the following on the screen:
    00 * * * * /Users/(username)/scripts/time.sh
    cron uses a specific time format which you can read about, and 00 represents "on the hour."
  4. Press Escape; this will take you out of insert mode, then type :wq!, and this will save your crontab file and quit the editor.
  5. Type exit to end your root shell.
At the top of the next hour (assuming it's not less than three minutes away), you should hear a male voice telling you what time it is. I hope this was a useful and educational experience for you.
    •    
  • Currently 2.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[12,161 views]  

Speak the time on the hour via Terminal | 8 comments | Create New Account
Click here to return to the 'Speak the time on the hour via Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Speak the time on the hour via Terminal
Authored by: troylanes on Jan 02, '08 07:50:56AM

Don't forget (on Leopard) to use the "-v Alex" switch to use the suave new voice.



[ Reply to This | # ]
Speak the time on the hour via Terminal
Authored by: Reaperducer on Jan 02, '08 08:30:20AM

What I've always wanted is a way to make the hourly time announcement in a foreign language (French, for example). It would be very useful for people learning a new language to hear the numbers on a regular basis.

I've tried changing my Mac's system language to French, but it still speaks the time in English.



[ Reply to This | # ]
Speak the time on the hour via Terminal
Authored by: fguilleme on Jan 02, '08 12:26:50PM

I had the same problem with the french voice. I use OSX in english with a qwerty keyboard but I like to hear the time in french using the proper form (5 heure moins le quart in place of the ugly 16 heure 45). So the only option was to use a simple shell script and cron. Associated with a nice voice such as those from assistiveware it makes a nice speaking clock.
Additoonnaly the voices can be used with adium to speak the various events instead of a stupid sound. It can even speak the message in case you're not in front of the screen.



[ Reply to This | # ]
Speak the time on the hour in French
Authored by: rickybuchanan on Jan 03, '08 01:21:08AM
A script like this would allow you to do that, as the say command has a -v voicename switch to specify which voice. So if you put whatever French text you want instead of the English text and specify the correct voice with the command, it will say the numbers in French automatically.

You'll need a French voice to do this with, such as the ones AssistiveWare sell - you can't get the default Apple voices to speak languages other than English.

Assuming your French voice was Alice the command would be (excuse my French) something like this:
say -v Alice Le temps est maintenant `date +%I` heures.
I think.

I don't actually use non-English voices - I just use both the American and British ones which is probably a little different - so if this doesn't work I suggest you consult Tom at The Multilingual Mac blog about it. It's definititely do-able though.

Ricky
ATMac - http://atmac.org/ - Assistive Technology for Mac OS X Users

---
[Please excuse mistakes/brevity, typed via on-screen keyboard due to disability]

[ Reply to This | # ]

Speak the time on the hour via Terminal
Authored by: barefootguru on Jan 02, '08 12:27:01PM
If you read the man page for crontab you'll see:
(Darwin note: Although cron(8) and crontab(5) are officially supported under Darwin, their functionality has been absorbed into launchd(8), which provides a more flexible way of automatically executing commands. See launchctl(1) for more information.)
There's lots of examples available around the web for creating your own plist files in ~/Library/LaunchAgents, e.g.: http://developer.apple.com/macosx/launchd.html

[ Reply to This | # ]
Speak the time on the hour via Terminal
Authored by: mmnw on Jan 02, '08 01:18:11PM

Except isn't very precise about Time. It has a known bug (or feature??) which makes the StartCalendarInterval (and in some cases the StartInterval) key virtually unusable. First StartInterval starts at "random" times, not at full or half hours like cron would do it (it just starts the job "roughly" every 60 minutes or 30 minutes or whatever you want). Then StartCalendarInterval gets totally out of it's time if you send your mac to sleep, it will just add the sleeping time to the time specified, which makes this key totally useless.
This is known to apple and discussed on the apple-forums in several topics (just search for StartCalendarInterval) and makes a launchd job totally unusable for this hint. That's why you would use cron for this, and why cron is still delivered with leopard.



[ Reply to This | # ]
Speak the time on the hour via Terminal
Authored by: rasbach on Jan 03, '08 10:21:30AM

This was my hint submission, sorry- I didn't log in when I submitted it. I appreciate the tip about -v Alex, I'll try that when I have a chance!



[ Reply to This | # ]
Speak the time on the hour via Terminal
Authored by: rasbach on Jan 03, '08 10:26:53AM

"This solution also has the advantage of running for all users, not just for the logged-in user."

That was really the main point of this, I leave my computer on and this works even when it's just sitting at the user logon screen, or when the kids are logged in on their accounts. The other option only worked when I was logged in.



[ Reply to This | # ]