|
|
Setting House Clocks after Power Outage
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") doneOr if you want it on one line:
This smoothed out iStat Menus and is more efficient. I like it!!
Setting House Clocks after Power Outage
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. Edited on May 03, '11 06:40:48AM by pub3abn
Setting House Clocks after Power Outage
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).
Setting House Clocks after Power Outage
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. |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.09 seconds |
|