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


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: 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 | # ]