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

Click here to return to the 'Script to say the time.' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Script to say the time.
Authored by: Anonymous on Jan 08, '02 01:19:04AM

I never posted this, but it's a script to speak the time. I have it running in my cron every 30 minutes, to remind me how late it is.

#! /bin/sh
if test `date +%H%M` = '1200'; then
/usr/bin/osascript 'say "It is 12 noon."';
elif test `date +%H%M` = '0000'; then
/usr/bin/osascript 'say "It is 12 midnight."';
elif test `date +%M` = '00'; then
date +'say "The time is, %I %p"' | sed s/AM/A-M/ | /usr/bin/osascript ;
date +'say "The time is, %I %M %p"' | sed s/AM/A-M/ | /usr/bin/osascript ;

I guess I can explain these commands. The "date" command emits the date. The `` backticks around that command cause the output (the date) to be inserted into the command line, replacing the command itself. `date +'blah'` uses 'blah' as a format string, in this case, some speakable text interspersed with date numbers.

sed is a "stream editor" -- it's basically search and replace on piped data. Here, it turns "AM" into "A-M" so the computer won't speak "am" (rhymes with ham).

The if--elif-else statements make the program say the right thing at the top of the hour, and at noon and midnight.

[ Reply to This | # ]
Script to say the time.
Authored by: Anonymous on Jan 08, '02 11:08:41AM

Nice, thank you for posting this. The simple scripts are always the handiest ones.

[ Reply to This | # ]