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

Setting House Clocks after Power Outage UNIX
My power went out yesterday. I wanted a quick way to set all the house clocks accurately and easily.

I used the Mac's speech ability and scriptability to make a quick talking clock. I ran this script and turned up my speakers and set all the clocks in the house with ease:
while [ 1 ];do z=`date +%S`;if [ `expr $z % 5` -eq 0 ];then say `date "+%l %M and %S seconds"`;fi;done
Paste into a terminal window and press enter. Type Control+C to quit.

[crarko adds: I tested this, and it works as described. Note that this is bash shell syntax; if you use a different shell you may need to modify the script accordingly. I give it an A for cleverness.]
    •    
  • Currently 3.40 / 5
  You rated: 3 / 5 (10 votes cast)
 
[6,600 views]  

Setting House Clocks after Power Outage | 21 comments | Create New Account
Click here to return to the 'Setting House Clocks after Power Outage' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Setting House Clocks after Power Outage
Authored by: Unsoluble on May 02, '11 08:21:02AM
Note that due to the relatively slow speed of sound, using this method could lead to navigation errors. I recommend installing a time ball in your living room instead. ;)

[ Reply to This | # ]
Setting House Clocks after Power Outage
Authored by: wallybear on May 02, '11 10:38:41AM

I hope you did this for fun, as using your wris*censored*ch is simpler and more accurate....



[ Reply to This | # ]
Setting House Clocks after Power Outage
Authored by: Unsoluble on May 02, '11 10:43:36AM

Nice catch, word filter.



[ Reply to This | # ]
Setting House Clocks after Power Outage
Authored by: tedw on May 02, '11 10:53:25AM

tooooo funny... :-)



[ Reply to This | # ]
oh...
Authored by: wallybear on May 02, '11 01:25:22PM

This is really fun: wrist_watch being censored because contains an offensive word inside...



[ Reply to This | # ]
Setting House Clocks after Power Outage
Authored by: bglnelissen on May 02, '11 11:45:12AM
Watch? btw, next time do a:

say -v Bubbles
Than you're really cool.
Edited on May 02, '11 11:56:01AM by bglnelissen


[ Reply to This | # ]
Setting House Clocks after Power Outage
Authored by: S Barman on May 02, '11 05:01:53PM
I have this thing about wasting processor cycles. When I ran this script, I watch as my iStat Menus bumped up my CPU usage. When I started a long time ago using Unix on a PDP 11, we had to worry about every processor cycle we used. Writing efficient scripts and programs are in my blood and I can't help myself. As I looked at this script, I thought I would add a bit of efficiency and smooth the bumps on iStat Menus.

First of all, using the test brackets with the one between them means the shell is going to run the test and return true. This is a bit inefficient. What you should use to run an infinite loop is the null command (":"). The null command does nothing but returns a 0 ("true" in shell parlance) value. There is nothing to evaluate and you save some cycles.

Then I noticed that the script loops continuously running the external command "date" and then uses the external command "expr" to do the arithmetic. I would rather have the script wait until the right time and not run on a continuous loop. Using the same basic arithmetic, I took the output from "date +%S", took the mod of 5, then used "sleep" to have the script pause for that many seconds. This prevents it from constantly running commands over and over again. I also used the internal arithmetic operations offered by the shell. As a result, the shell script looks like:

while :
do
        z=$(date +%S)
        sleep $((5-$z%5))
        say $(date "+%l %M and %S seconds")
done
Or if you want it on one line:

while :; do z=$(date +%S); sleep $((5-$z%5)); say $(date "+%l %M and %S seconds"); done;

This smoothed out iStat Menus and is more efficient. I like it!!

[ Reply to This | # ]

Setting House Clocks after Power Outage
Authored by: pub3abn on May 03, '11 06:37:24AM

After confirming that S Barman's script actually consumed fewer processor cycles, I used Platypus to create an app package for the script, using a free (no fee or attribution required for any use) icon from http://www.iconfinder.com/. Basically this gives you a cute app you can run without firing up the terminal.

It can be downloaded from here:

http://www.mediafire.com/?s5ci3j7yybeqf8u

If you don't want to risk installing something from an untrusted source (like me! ... even though I'm completely trustworthy ... I promise!), it is extremely easy to build this yourself using Platypus, which is free. You can get Platypus from here: http://www.sveinbjorn.org/platypus. And the icon I used is available here: http://www.iconfinder.com/icondetails/54062/256/.

Edited on May 03, '11 06:40:48AM by pub3abn



[ Reply to This | # ]
Setting House Clocks after Power Outage
Authored by: kevans on May 03, '11 04:33:04PM

When I run the app on a Mac Mini with Snow Leopard 10.6.7, it stops announcing the time after a few repetitions. Sometimes, the app stops after 20 sec (5 announcements) and sometimes after 30 sec (7 announcements).



[ Reply to This | # ]
Setting House Clocks after Power Outage
Authored by: pub3abn on May 04, '11 06:10:40AM

It did that to me once or twice while I was testing it, but I thought maybe it was a system glitch. I'm not sure why it would do that. I tried it again now, and it went on and on, so I am at a loss to explain why it would do that sometimes. I am also running 10.6.7. Perhaps there is something in the script that would cause it to hang under certain circumstances.

You could try the High CPU version of the app, based on the original script, to see if it works better:

http://www.mediafire.com/file/7isezthw3v7yc2h/Speak%20the%20Time%20HC.app.zip



[ Reply to This | # ]
Setting House Clocks after Power Outage
Authored by: Beweis on May 04, '11 12:45:58AM

Does anybody know how I can wrap this in an applescript?



[ Reply to This | # ]
Setting House Clocks after Power Outage
Authored by: jsdetwiler on May 04, '11 06:06:23AM

Use Automator (part of OS X). Select Application then add a single Action, "Run Shell Script." Select "/bin/bash" from the Shell drop-down and replace the contents of the input box with the script.



[ Reply to This | # ]
Setting House Clocks after Power Outage
Authored by: ascanio on May 04, '11 01:10:43AM

I think I am missing something: do your clocks set themselves hearing the proper time? My clocks don't.
Otherwise I don't see the point.

A.



[ Reply to This | # ]
Setting House Clocks after Power Outage
Authored by: pub3abn on May 04, '11 05:59:38AM

The Mac OS X clock syncs with internet time servers, so it should be accurate. This script causes your Mac to announce the time audibly, so you can walk around the house and adjust your unsynchronized clocks to the correct time while listening to time being announced from your Mac.



[ Reply to This | # ]
Setting House Clocks after Power Outage
Authored by: Mac Berry on May 04, '11 05:08:39AM

Hmm, very clever! But, it takes 2.1 seconds to announce the time, which is an error of nearly 50% over the 5 second granularity! Do I set the clock on my microwave at the start, end, or midpoint of the announcement? ;)

It needs "at the third stroke it will be…." added, as it could make all the difference when I come to heat my Horlix!

Edited on May 04, '11 05:10:24AM by Mac Berry



[ Reply to This | # ]
Setting House Clocks after Power Outage
Authored by: jsdetwiler on May 04, '11 06:14:41AM
You're correct: you'd need to set the clock at the start of the message. Programming it to announce the time ahead of a synchronized tone would be a good challenge for a different day.

[ Reply to This | # ]
With added beeps!
Authored by: applescripter on May 04, '11 10:49:54AM
I realise you were joking, but ask and you shall receive

sleep $((10-$(date +%S)%10)) ; while :; do t=$SECONDS; say "At the third beep the time will be $(date -v +10S "+%l %M and %S seconds")"; sleep $((10+$t-$SECONDS-2)); printf "\a"; sleep 1 ; printf "\a"; sleep 1; printf "\a"; done
Edited on May 04, '11 11:50:04AM by applescripter


[ Reply to This | # ]
With added beeps!
Authored by: Mac Berry on May 05, '11 01:50:23AM

Ooh neat!

So next, can I have a white Aston Martin DB9 please?

Mark



[ Reply to This | # ]
With added beeps!
Authored by: asmeurer on Jul 31, '11 06:23:33PM

You forgot to mention that you have to enable audible beeps in the Terminal preferences. Some of us have turned them off.

Also, I should note that this is better for another reason, which is that the say command takes some time to compile the string into audio before it is played, which is more of a delay.



[ Reply to This | # ]
Setting House Clocks after Power Outage
Authored by: ascanio on May 04, '11 09:39:39AM

"pub3abn:
The Mac OS X clock syncs with internet time servers, so it should be accurate. This script causes your Mac to announce the time audibly, so you can walk around the house and adjust your unsynchronized clocks to the correct time while listening to time being announced from your Mac."


This is what I understood. So, I don't get the point with this hint.
Much ado about nothing, someone would say…

A.



[ Reply to This | # ]
Setting House Clocks after Power Outage
Authored by: Mac Berry on May 05, '11 04:53:32AM

In the olden days (the 70's), when you got a new watch, didn't you phone up the speaking clock to get an accurate time check to set it by? This hint gives you that, without the cost of phoning the speaking clock.

There are other ways to do it of course, such as use your mobile's (synced?) clock, or your watch, or whatever, but this hint seems to me to be a good way to get an accurate time check that allows you to set clocks that have no internet connection.



[ Reply to This | # ]