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

Give your battery a thorough checkup System
There has recently been discussion in some online forums (Slashdot and Apple) about the Mac OS 10.2.4 upgrade reducing the capacity of some laptop batteries. Some have thought it might not be a hardware problem, but instead that the system is merely underreporting the battery capacity. And it definitely has not affected everyone, as some people report they are either unaffected or improved by the update.

Because of this, it becomes more important than ever for owners of Apple laptops to monitor their battery's capacity. There are some easy ways to do this. If you want to go the very easy route, there are two applications out there that are of use here: X-Charge and XBattery. X-Charge is freeware, but X-Battery has a modest $15 shareware fee and has a great deal more features.

There is also a Unix script that was written by Matthew Pearson of Sun ESP Software.

[robg adds: Read the rest of the article for the script, along with some selected results and quotes from people who have run it on their portables.]

The script:

#!/bin/bash

[ -x /usr/sbin/ioreg ] && \
    /usr/sbin/ioreg -p IODeviceTree -n "battery" -w 0 | \
    sed -ne '/| *{/,/| *}/ {
        s/^[ |]*//g
   /^[{}]/!p
    }' | \
    awk '/Battery/ {
    gsub("[{}()\"]","", $3)
      gsub(","," ",$3)
  split($3,ct," ")
  # extract flag value and convert to hex
       sub("Flags=","",ct[2])
        str=sprintf("Flags=%d/0x%03x",ct[2],ct[2])
    sub("Flags=[0-9]*",str,$3)
        # get max and current charge levels
   sub(".*=","",ct[4])
   sub(".*=","",ct[5])
   printf("%s [%.1f%%]\n",tolower($3),100*ct[5]/ct[4])
    }'

# EOF

I am not sure if ioreg is installed with the basic Apple installation. I do know that the GUI for that command, IORegistryExplorer, is one of the Developer Tools. Make sure to set the executable bit (chmod +x script_name). This script produces the following output:

voltage=# flags=[hex value] amperage=# capacity=# current=# [##.#%]

The results for "capacity" and "current" are in microamperes per hour (mAh).

For comparative purposes, here are a few people's results from this script, along with their comments about the state of their system.

voltage=11928 flags=4/0x004 amperage=1023 capacity=4192 current=3692 [88.1%]

"FWIW, the output on my 88% charged iBook 800 (12", combo drive, november '02 model, bought in January) ... I can squeeze 5+ hours out of this (just typing text, screen dimmed to the one but darkest setting, CPU speed set to 'automatic'), so the battery is definitely good." [link]

voltage=16670 flags=5/0x005 amperage=1200 capacity=4017 current=3928 [97.8%]

"A friend of mine who has a newer machine."

voltage=16564 flags=5/0x005 amperage=1200 capacity=2942 current=2931 [99.6%]

"My TiBook 500 ... i have no idea what it was doing before the updates, but i leave it plugged in 24/7." [link]

voltage=10943 flags=4/0x004 amperage=983 capacity=1814 current=1570 [86.5%]

"I own a 500 MHz iBook and over the last few months my battery has precipitously dropped from 3 hours/charge to as low as 45 minutes a charge."

voltage=12236 flags=5/0x005 amperage=1200 capacity=219 current=214 [97.7%]

"My battery is very sick." [link]

My own results are:

voltage=16666 flags=5/0x005 amperage=1200 capacity=3544 current=3538 [99.8%]

Like the first individual, I can turn my brightness down to the lowest possible setting and still get about five hours' worth of battery use from my system. But God knows, I'm going to be very closely monitoring my battery capacity, and the 'Battery Capacity' graph in XBattery will prove to be very helpful in this regard.

So, the question remains: how do you compare your end result to what your battery should be, fresh from the factory? Just check it against this Knowledge Base entry. Using this, for example, I can tell that a fresh battery for my 14.1" iBook would be at 3.9 Ah, and thus my 3.544 Ah battery still has 91% of its original capacity. Of course, I'm not 100% sure of this, given that the 12" iBook owner above claims to have a capacity of 4.192 Ah, when the article says that said battery has a 3.9 Ah maximum.

ADDENDUM: The Knowledge Base article cited above may not be accurate for determining your battery's original, brand new capacity. When your voltage is multiplied by your capacity, does it match up with what the Apple Store advertises as your particular battery's watt-hour capacity?

iBook (12.1") - 42 watt-hours
iBook (14.1") - 56 watt-hours

PowerBook (12.1") - 47 watt-hours
PowerBook (15.2") - 61 watt-hours
PowerBook (17") - 55 watt-hours

Look at magitekkn's comments below for further exploration and analysis.

[robg adds: This works as expected, and is a very nice tool! It's now a permanent fixture on our iBook G3/500...]

    •    
  • Currently 2.00 / 5
  You rated: 2 / 5 (3 votes cast)
 
[68,805 views]  

Give your battery a thorough checkup | 66 comments | Create New Account
Click here to return to the 'Give your battery a thorough checkup' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Give your battery a thorough checkup
Authored by: leffo on Mar 13, '03 10:52:21AM

This is what my two days old iBook 700 (12") reports with the above script:

voltage=12620 flags=5/0x005 amperage=1200 capacity=4148 current=4139 [99.8%]

Great hint though. I'm running 10.2.1 on this machine and will wait for 10.2.5 before I upgrade. Don't want to risk my batterypower!



[ Reply to This | # ]
Give your battery a thorough checkup
Authored by: wilkens on Mar 13, '03 03:01:13PM

No problems with 10.2.4 here. A seven month old iBook 600 running 10.2.4 gives:

voltage=12400 flags=5/0x005 amperage=1200 capacity=4149 current=4091 [98.6%]



[ Reply to This | # ]
Give your battery a thorough checkup
Authored by: rasda on Dec 19, '03 11:27:29AM

i have a pismo 400 for 2 and a half years. my first battery drains in the guarantee time so i got a new one which was very fast drained out too. i don't know why. a friend of mine has the same pismo and his battery is still cool. he bought it before mine. he has another power supply. it has the same form but shorter cables. maybe my power supply is not working correctly cause i get strange numbers when i run the script with power supply connected.

here with power supply:
capacity=197 amperage=1272 current=0 voltage=12154 flags=0/0x000 capacity=10000 amperage=1200 current=0 voltage=0 flags=838860931 [6901933.0%]

and here without:
capacity=197 amperage=1200 current=197 voltage=12398 flags=0/0x000 capacity=10000 amperage=1200 current=0 voltage=0 flags=32 [0.0%]

i will try the power supply of my friend.

cheers
rasda



[ Reply to This | # ]
Give your battery a thorough checkup
Authored by: wOOge on Mar 13, '03 10:56:31AM
i have an iBook 500 (Dual USB) and ran the script to find out where i'm at:

The norm for my ibook is a capacity of 3.9 I'm running a capacity of 2.493

I always knew my battery was kacking out on me... now i just have proof..!!

here was my script's output: voltage=11901 flags=7/0x007 amperage=1200 capacity=2493 current=1545 [62.0%]



[ Reply to This | # ]
Give your battery a thorough checkup
Authored by: lockley on Mar 13, '03 03:44:24PM

I have a Dual USB iBook from July 2001 and here are my reading just after I have removed the power cable and the iBook has finished calculating.

voltage=12313 flags=4/0x004 amperage=1200 capacity=1431 current=1426 [99.7%]

My capacity seems to be way down. I only upgraded to Jaguar (then 10.2.3) at beginning of Feb. this year. When I was running 10.1.5 I was always getting well over of 2 hours of battery time being displayed in the menu bar, but now I'm lucky if I get 1:30 hours. Time for a new battery, or wait for 10.2.5?

How come I get the same flags value (4/0x004) as tamenti "Making a log?" comment? And what is the flag value anyway (I know it is a Hex value)?

Other than that, Jaguar and 10.2.4 is going great. No other side-effects of the 10.2.4 upgrade that others have reported.



[ Reply to This | # ]
So, what do you do next?
Authored by: porkchop_d_clown on Mar 13, '03 10:59:01AM

Assuming that your battery is under-performing (as mine is) what can you do? I know with old Ni-Cads you can restore some level of performance by "exercising" the battery. Is there a way to do this with my iBook battery?

---
--
knock knock



[ Reply to This | # ]
What you can do....
Authored by: wOOge on Mar 13, '03 11:29:31AM

check out this article... it basically says that Lithium Ion batteries are known to loose charge noticibally over one year, and dramatically begin to fail after 2 years...

http://www.powerpulse.net/powerpulse/archive/aa_040201b3.stm

oh and btwn.. theres not much we can do about it... :(

yay!!.....

/sarcasm



[ Reply to This | # ]
Plugged In?
Authored by: Enkerli on Mar 13, '03 11:12:10AM

Err, this may sound stupid, but are these tests done while the machine is plugged in? If so, I get my full 100% on my iBook 500 (Dual USB):
voltage=12254 flags=4/0x004 amperage=1200 capacity=2882 current=2882 [100.0%]

My machine is plugged in most of the time and seems to give me decent performance when on battery.



[ Reply to This | # ]
Plugged In?
Authored by: wOOge on Mar 13, '03 11:22:47AM

notice youre capacity 288.. .... that's your batterys BEST capacity. It's supposed to be 3900 or better. So plugged in or not, you're suffering from the same problem as I and many other Ibook 500 owners...



[ Reply to This | # ]
Making a log?
Authored by: tamenti on Mar 13, '03 11:12:41AM

How do I make a log with the info given by this script?
% ./scriptname > battery.log
Puts the output of the script into the file, but how do I append new data to the end of the file and maybe add a timestamp? Can it be done in a single command or would it have to be build into the script itself?

Oh, and, by the way, my almost-a-year-old iBook 600 gives this:
voltage=11384 flags=4/0x004 amperage=1110 capacity=2054 current=1690 [82.3%]
So if I read the knowledgebase right, my book is a at about half capacity?



[ Reply to This | # ]
Making a log?
Authored by: jpryor68 on Mar 13, '03 11:30:59AM
How do I make a log with the info given by this script?
% ./scriptname > battery.log
Puts the output of the script into the file, but how do I append new data to the end of the file and maybe add a timestamp? Can it be done in a single command or would it have to be build into the script itself?

This appends a timestamp and scriptname's output to a log file:
% date;scriptname >> logfile.log

[ Reply to This | # ]

Shell Scripting
Authored by: ktohg on Mar 13, '03 07:26:24PM

Don't wish to intrude but this will not work as expected

The semi coloen is a command delimeter so the date command will have default input and output where as the other command will have output redirected to the log file.

To accomplish what you wish you can do it two ways. (The first I belive may not be supported in every shell.

% (date ; scriptname) >> logfile.log

or

% date >> logfile.log ; scriptname >> logfile.log

[ Reply to This | # ]
Making a log?
Authored by: Garin on Mar 13, '03 11:31:39AM

you could do something like:

echo `date; scriptname;` >> battery.log

If you do ">>" instead of ">" it will append to the end of the file rather than overwriting it. By enclosing two commands inside the backticks "``" these two commands will be executed, returning their output. Putting "echo" in front of it will dump out the results as text (otherwise the shell would try to execute the returned text).



[ Reply to This | # ]
Making a log?
Authored by: Garin on Mar 13, '03 11:35:58AM

Ah yes. The "echo" can be safely omitted when using csh, though it won't hurt to have it in there. With bash, you have to include it or it won't work.



[ Reply to This | # ]
Making a log?
Authored by: Garin on Mar 13, '03 11:41:32AM

*sigh* nevermind. Don't omit the "echo". You'll need the entire command as I originally posted it, in both csh and bash. Otherwise, either you won't get the timestamp in the log file, or the shell will try to execute the resulting text.



[ Reply to This | # ]
Give your battery a thorough checkup
Authored by: JoeGrind on Mar 13, '03 11:51:17AM
Well, that's odd. I have a PowerBook G4 maybe a month or so old. That article says my battery capacity should be 3.9 Ah but this is the output of that little script...

voltage=15817 flags=4/0x004 amperage=1019 capacity=6236 current=5593 [89.7%]
Furthermore, my machine goes to sleep at what is listed as 30% capacity without so much as a warning.

[ Reply to This | # ]
Give your battery a thorough checkup
Authored by: xchanyazy on Mar 13, '03 12:11:37PM

Re: JoeGrind

Same thing here, with a 700 mHz iBook. It says I have about 45 minutes to an hour left, then, poof, black screen and sleeping.



[ Reply to This | # ]
Give your battery a thorough checkup
Authored by: xchanyazy on Mar 13, '03 12:13:28PM

Re: JoeGrind

Same thing here, with a 700 mHz iBook. It says I have about 45 minutes to an hour left, then, poof, black screen and sleeping.

Sorry, this is my output:

voltage=12442 flags=5/0x005 amperage=1200 capacity=3098 current=3089 [99.7%]



[ Reply to This | # ]
I checked mine: they are bad
Authored by: SOX on Mar 13, '03 01:09:02PM

Before I read about this problem I had been thinking something was wrong with my battery. I could never "catch it in the act" but it seemed like one moment I would have lots of charge and then poof it would drop from an hour of reserve time to sleep mode.

So I left X charge running and here is what I saw.

I have two batteries an old one and a one less than 6 months old. the old one would discharge too between 45 and 55% then drop instantly to 1% charge (I mean instantly). When I recharged it, it would charge assymtotically to around 45% then instantly pop up to 100% charge.

on my new battery this discharge sudden drop occured at around 25% remaining charge. however I did not observe the sudden increace during the charging process. this one charges assymtotically to 99%.

I tried resetting the PMU but this changed nothing. I also zapped the parameter ram.

I'm not sure if this is something I should complaain or not. after all I have read that all Li have a lifetime of around 500 charge cycles before they decay. even though I keep mine plugged in most of the time I think that in 6 months use anyone would encounter around 500 recharging events. So I'm not sure if I should be unhappy with this performance.

I think that if there is a problem its with the software not reporting the dimished capacity properly. If it had I would just have noted a lower capacity rather than a sudden drop and been much less alarmed.



[ Reply to This | # ]
I checked mine: they are bad
Authored by: mattmoss on Mar 13, '03 04:32:45PM

I get the battery instant discharge as well. At 100%, the menubar indicator gives me about 1:30. But it usually only makes it about 30 minutes (to around 60%) where it instantly discharges to 1% and goes to sleep. Verified looking at the pretty little lights on the battery.

I've had my dual-usb iBook 500 for 1.5 yrs now, so who knows how bad the battery really should be? This is what I get from the script at full charge, plugged in:

voltage=12389 flags=5/0x005 amperage=1200 capacity=1752 current=1746 [99.7%]

Strangely, one of the other symptoms I see is that every once in a while, even while the battery is at full charge and plugged in for hours, the light on the charger plug goes from green (ok) to orange (charging).



[ Reply to This | # ]
I checked mine: they are bad
Authored by: everydayjoe on Mar 13, '03 05:55:21PM

"
Strangely, one of the other symptoms I see is that every once in a while, even while the battery is at full charge and plugged in for hours, the light on the charger plug goes from green (ok) to orange (charging).
"

I've noticed the same thing (green to orange to green) with mine - iBook 600Mhz, dual USB, about 1.5 years old. Battery performed better after running the 10.2.4 Combo Updater and then repairing permissions, but definitely not as well as before 10.2.4.

-jonathan



[ Reply to This | # ]
Same problem here -- Call AppleCare!
Authored by: dcheng on Mar 13, '03 05:34:21PM

A few months back, I had the exact same problem with my iBook G3/600 (16 VRAM) battery. It would drain normally from 100% down to about 50%, at which point the charge would abruptly drop to zero and the machine would go to sleep.

A quick call to Apple tech support had me resetting the PRAM, NVRAM, power manager, and other "standard" things, but to no avail.

It was quickly determined that my four-month old battery was defective, and I was couriered a replacement the following day under the AppleCare warranty.

I believe "decent" battery performance is covered under the AppleCare extended warranty plan. I recharge my battery at least once a day, so I can easily reach the "average" life-expectancy of 500-600 cycles for Li-Ion cells before a year is up. Considering the cost of a new iBook battery, the AppleCare warranty will pay for itself in new batteries alone!

FWIW, my replacement iBook battery that's about four months and maybe 200 charge-cycles old shows:

voltage=12540 flags=5/0x005 amperage=1200 capacity=3645 current=3645 [100.0%]

with noticably worse -- but still acceptable -- performance from when it was new. It equates to around four hours of continous, low-processor use with the screen brightness at 10%.

-Dave

[ Reply to This | # ]

Give your battery a thorough checkup
Authored by: CraigStanton on Mar 13, '03 01:53:32PM

<code>voltage=0 flags=32/0x020 amperage=1200 capacity=10000 current=0 voltage=11806 flags=4 amperage=1122 capacity=774 current=739 [0.0%]</code>

that is from my 2.5 year old Pismo. I am currently on 83% which is 26 minutes according to OS X, strangely the script for this hint thinks i have 0%



[ Reply to This | # ]
Give your battery a thorough checkup
Authored by: lestmak on Mar 13, '03 05:48:53PM

Has the same problem with my Pismo, until I realised all I had to do is swap the battery in the bays (i.e. put the battery in the bay that your DVD drive normally sits.) The script should then run fine with a nice % at the end



[ Reply to This | # ]
Discharge cycles
Authored by: SOX on Mar 13, '03 02:10:07PM

Does the powerobook or OS keep track of the number of discharge cycles a battery or computer has gone through? This is a better indicator of effective battery age than simple time.

also what do those flags and stuff mean?



[ Reply to This | # ]
Discharge cycles
Authored by: mattmoss on Mar 13, '03 04:40:50PM

I haven't gone looking for any docs, but this is what I quickly figured out:

bit 0: power adapter present
bit 1: charging
bit 2: ??? (always 1?)
bit 3-6: ??? (always 0?)
bit 7: battery missing

Don't know bits? Here's the few flag values I saw:

flags=4: battery in, power adapter out
flags=5: battery in, power adapter in
flags=7: battery in, power adapter in, charging battery
flags=131: battery out, power adapter in



[ Reply to This | # ]
Discharge cycles "Flags"=133
Authored by: robx on Mar 14, '03 06:01:42AM

have two batteries on a lombard with strange flags, whats wrong?
1:
% /usr/sbin/ioreg -p IODeviceTree -n battery -w 0 | sed -n '/battery/','/}$/'p
| | +-o battery@3
| | | {
| | | "reg" =
| | | "AAPL,phandle" =
| | | "device_type" =
| | | "name" =
| | | "IOBatteryInfo" = (
{"Voltage"=12657,"Flags"=133,
"Amperage"=1055,"Capacity"=4425,"Current"=0},
{"Voltage"=0,"Flags"=1,
"Amperage"=0,"Capacity"=0,"Current"=0})
| | | }

2:
% /usr/sbin/ioreg -p IODeviceTree -n battery -w 0 | sed -n '/battery/','/}$/'p
| | +-o battery@3
| | | {
| | | "reg" =
| | | "AAPL,phandle" =
| | | "device_type" =
| | | "name" =
| | | "IOBatteryInfo" = (
{"Voltage"=11154,"Flags"=133,
"Amperage"=1055,"Capacity"=2642,"Current"=0},
{"Voltage"=0,"Flags"=1,
"Amperage"=0,"Capacity"=0,"Current"=0})
| | | }
BOTH:
% /usr/sbin/ioreg -p IODeviceTree -n battery -w 0 | sed -n '/battery/','/}$/'p
| | +-o battery@3
| | | {
| | | "reg" =
| | | "AAPL,phandle" =
| | | "device_type" =
| | | "name" =
| | | "IOBatteryInfo" = (
{"Voltage"=11154,"Flags"=133,
"Amperage"=1200,"Capacity"=2642,"Current"=0},
{"Voltage"=12520,"Flags"=133,
"Amperage"=1200,"Capacity"=4425,"Current"=0})
| | | }



[ Reply to This | # ]
Flags and alternative script
Authored by: hayne on Jun 26, '03 03:03:42AM

I discovered a similar, but more elaborate, script that uses the same (ioreg) method but has various display modes.
The author of this script has figured out what all the flags mean.
Script and documentation available from:
http://www.mitt-eget.com/software/macosx/



[ Reply to This | # ]
Give your battery a thorough checkup
Authored by: Anonymous on Mar 13, '03 04:38:13PM
First, a clarification: XBattery is shareware with a $15 registration fee, not freeware. X-Charge is freeware, but definitely nearly as featured. I'll ask Rob to make the change when I get home this evening.

Second, as to what the flags mean:

'flags' is usually 0x004 when you're unplugged, 0x005 when you're plugged in, and 0x08_ or 0x09_ when you're low on juice. I presume each bit has a special meaning but I don't care enough to poke through the Darwin source.

That's from the posting you read when you click on the "bash script" link above.

[ Reply to This | # ]

Give your battery a thorough checkup
Authored by: Anonymous on Mar 13, '03 04:40:44PM

Sigh. This is not a good day for me. I meant to say that X-Charge is NOT nearly as featured as X-Battery is.



[ Reply to This | # ]
XBattery is not freeware N/T
Authored by: rameeti on Mar 13, '03 04:41:13PM

No big deal, just a clarification.



[ Reply to This | # ]
Give your battery a thorough checkup
Authored by: robx on Mar 13, '03 05:39:18PM

have very strange values: with two batteries on LOMBARD {right slot}
1:
voltage=11161 flags=133/0x085 amperage=1200 capacity=2642 current=0 voltage=0 flags=1 amperage=0 capacity=0 current=0 [0.0%]
2:
voltage=12699 flags=133/0x085 amperage=1200 capacity=4425 current=0 voltage=0 flags=1 amperage=0 capacity=0 current=0 [0.0%]

please help- need some information about the flags, whats wrong??



[ Reply to This | # ]
show the raw data
Authored by: gcole on Mar 13, '03 08:41:19PM
Try this, and post the results; it may indicate where the issue lies.

/usr/sbin/ioreg -p IODeviceTree -n battery -w 0 | sed -n '/battery/','/}$/'p

(That's "w zero pipe" after the first "battery", where pipe is probably shift-\.) The sed portion shows everything between "battery" and the next line that ends in "}", which is the end of the battery block.

[ Reply to This | # ]

-> the raw data
Authored by: robx on Mar 14, '03 05:41:40AM
1:
% /usr/sbin/ioreg -p IODeviceTree -n battery -w 0 | sed -n '/battery/','/}$/'p
      | | +-o battery@3  
      | | |   {
      | | |     "reg" = 
      | | |     "AAPL,phandle" = 
      | | |     "device_type" = 
      | | |     "name" = 
      | | |     "IOBatteryInfo" = (
{"Voltage"=12657,"Flags"=133,
"Amperage"=1055,"Capacity"=4425,"Current"=0},
{"Voltage"=0,"Flags"=1,
"Amperage"=0,"Capacity"=0,"Current"=0})
      | | |   }

2:
% /usr/sbin/ioreg -p IODeviceTree -n battery -w 0 | sed -n '/battery/','/}$/'p
      | | +-o battery@3  
      | | |   {
      | | |     "reg" = 
      | | |     "AAPL,phandle" = 
      | | |     "device_type" = 
      | | |     "name" = 
      | | |     "IOBatteryInfo" = (
{"Voltage"=11154,"Flags"=133,
"Amperage"=1055,"Capacity"=2642,"Current"=0},
{"Voltage"=0,"Flags"=1,
"Amperage"=0,"Capacity"=0,"Current"=0})
      | | |   }
BOTH:
% /usr/sbin/ioreg -p IODeviceTree -n battery -w 0 | sed -n '/battery/','/}$/'p
      | | +-o battery@3  
      | | |   {
      | | |     "reg" = 
      | | |     "AAPL,phandle" = 
      | | |     "device_type" = 
      | | |     "name" = 
      | | |     "IOBatteryInfo" = (
{"Voltage"=11154,"Flags"=133,
"Amperage"=1200,"Capacity"=2642,"Current"=0},
{"Voltage"=12520,"Flags"=133,
"Amperage"=1200,"Capacity"=4425,"Current"=0})
      | | |   }
     

[ Reply to This | # ]
Give your battery a thorough checkup
Authored by: sinebubble on Mar 13, '03 06:23:58PM

I have a Pismo500 and I have also noticed I get down to 45 minutes and the system goes to sleep. I just assumed it was a bad battery, but it looks like I"m not alone...

Plugged in:

voltage=0 flags=1667/0x683 amperage=1200 capacity=10000 current=0 voltage=12281 flags=1541 amperage=1200 capacity=2040 current=2032 [0.0%]



[ Reply to This | # ]
Give your battery a thorough checkup
Authored by: kb5ql on Mar 13, '03 06:50:04PM

This hint is great in that I was able to take the command, and parse the relevant info in perl, then pop up an applescript alert. This is great for giving yourself a warning in phases instead of waiting for the battery indicator to go red.

Now you may say, why, since the icon on the menubar already does this? I guess I hate having the battery icon take up half the menubar with the remaining percentage on it.

copy the following to a plain text file save as .battery_check.pl in your home dir (or wherever)

---START SCRIPT--- copy after this
#!/usr/bin/perl -w

use strict;

my $threshold = $ARGV[0];

#if no value passed to script use default check value of 15% or less
#before we start with the whiny applescript warnings

if (!$threshold) { $threshold = 15; }

my $osascript_name = "/tmp/battery_check.scpt";
my (%plist,$msg);
my @cmd_output = `/usr/sbin/ioreg -p IODeviceTree -n "battery" -w 0`;

#looking for the following string:

#"IOBatteryInfo" = ({"Voltage"=11925,"Flags"=4,"Amperage"=1705,"Capacity"=4149,"Current"=3717})

foreach my $line (@cmd_output)
{
if ($line =~ /IOBatteryInfo/i) { %plist = &formatBatteryInfo($line); }
}

#foreach (keys %plist) { print "$_ => $plist{$_} \n"; }

#my $voltage = sprintf("%.2f", ($plist{'Voltage'}/1000));
#this calculates the remaining charge left...
my $percentage = sprintf("%.1f", ($plist{'Current'}/$plist{'Capacity'})*100);
$msg = "\"Voltage : $plist{'Voltage'} Amperage: $plist{'Amperage'}\"" . '& return &';
$msg .= "\"Capacity : $plist{'Capacity'} Current: $plist{'Current'}\"" . '& return & return &';
$msg .= "\"Remaining Charge : [$percentage%] \"" . '& return & return';

if ($percentage < $threshold)
{
(my $osascript = <<"eoj") =~ s/^\t+//gm;
tell application "Finder"
set myAlert to $msg
display dialog myAlert buttons {"OK"} with icon caution
end tell
eoj

open(OUTFILE,">$osascript_name");
print OUTFILE $osascript;
close(OUTFILE);

system("osascript $osascript_name");
}
#### SUBS #####

sub formatBatteryInfo
{
my %plist;
my $info = shift;

$info =~ s/^.+"IOBatteryInfo"([^\{]+)\{([^\}]+)\}.+/$2/i;
#sample result from this regex:
#"Voltage"=11572,"Flags"=4,"Amperage"=1894,"Capacity"=4149,"Current"=3298
my @name_values = split(/,/,$info);
foreach my $pair (@name_values)
{
if ($pair =~ /"([^"]+)"\s*=\s*(.+)/) { $plist{$1} = $2; }
}

foreach (keys %plist) { $plist{$_} = sprintf("%.2f", ($plist{$_}/1000)); }

return %plist;
}

--END SCRIPT -- don't copy this line

you invoke this script by running it from the command line:

perl /Users/<yourname>/.battery_check.pl 15

This will only show an alert if you have 15% or less remaining charge.

After you have done this, you can set up a cron job to run this whenever you like. Thanks for the command tip for getting this info!

Here are my crontab entries for the script:

*/30 * * * * perl /Users/mjelks/.battery_check_alert 40 > /tmp/batt.log 2>&1
*/5 * * * * perl /Users/mjelks/.battery_check_alert 8 > /tmp/batt.log 2>&1

it will check every 30 mins for a charge of 40% or less , the second line will check for a charge of 8% or less every 5 mins



[ Reply to This | # ]
Energy Saver Scripts
Authored by: verence on Mar 13, '03 07:52:50PM

Does anyone know of an applescript to modify the current energy saver profile? This would be exteremely handy.



[ Reply to This | # ]
Give your battery a thorough checkup
Authored by: magitekkn on Mar 13, '03 08:47:41PM

Having given my TiBook 667's battery the run though today I received 3 hours of use off of a 98% charge, the computer was left recording with XBattery and sat with the monitor at 1 mark (no monitor sleep, no system sleep) and iTunes playing mp3s. Battery usage was linear down to the point at which the system auto slept. The capacity as reported by XBattery was 3.5Ah (3500mAh), with a battery voltage of ~16v, the power capacity of the battery equals 54.25Wh (15.5vdc*3.5A*h)this is well in line with 55Ah rating given by apple. The newer TiBooks (867, 1GHz) come with a larger 61Wh battery, which should have a current capacity of 3.94Ah.

(voltages are based off of the values taken from XBattery, not the 14.4v rating of the battery from the label.)



[ Reply to This | # ]
Give your battery a thorough checkup
Authored by: Anonymous on Mar 13, '03 10:52:42PM
Interesting comment, and it sure speaks better of my own iBook capacity ... it makes me wonder if the Knowledge Base article is wrong.

XBattery reports my capacity as 3.544 Ah and my voltage as 16.058v. Multiply the two together and I get 56.9096 watt-hours, which is actually a little above what the Apple Store describes as the capacity of the battery: "A 56-watt-hour rechargeable lithium ion battery that provides up to 6 hours of operation depending on battery saving features used and system configuration. This battery is compatible only with iBook 14.1" TFT displays."

Here are the numbers I grabbed from the battery descriptions at the Apple store:

iBook (12.1") - 42 watt-hours
iBook (14.1") - 56 watt-hours

PowerBook (12.1" TFT) - 47 watt-hours
PowerBook (15.2" TFT) - 61 watt-hours
PowerBook (17" TFT) - 55 watt-hours

Let's play this multiplication game with some of the numbers above from the original hint:

voltage=11928 flags=4/0x004 amperage=1023 capacity=4192 current=3692 [88.1%]

50.0022 watt-hours on a 12.1" iBook. (Possibly erroneous, considering a 12.1" iBook battery supposedly has a 42 watt-hour capacity.)

voltage=16670 flags=5/0x005 amperage=1200 capacity=4017 current=3928 [97.8%]

66.9634 watt-hours on a "newer machine" -- it's close to the stats of a 15.2" Powerbook.

voltage=16564 flags=5/0x005 amperage=1200 capacity=2942 current=2931 [99.6%]

48.7313 watt-hours on a TiBook; this could be a 12.1" TiBook.

voltage=10943 flags=4/0x004 amperage=983 capacity=1814 current=1570 [86.5%]

19.8506 watt-hours on a 500 mHz iBook. Whether it's compared to the 42 watt-hour or 55 watt-hour figure, this is a depleted battery.

voltage=12236 flags=5/0x005 amperage=1200 capacity=219 current=214 [97.7%]

2.6797 watt-hours on a "very sick" battery. Yup, it's sick. :)

Now, let's look at the ones in the comments:

leffo: voltage=12620 flags=5/0x005 amperage=1200 capacity=4148 current=4139 [99.8%]

52.3478 watt-hours on leffo's iBook.

wilkens: voltage=12400 flags=5/0x005 amperage=1200 capacity=4149 current=4091 [98.6%]

51.4476 watt-hours on wilkens' iBook.

wOOge: voltage=11901 flags=7/0x007 amperage=1200 capacity=2493 current=1545 [62.0%]

29.6692 watt-hours on wOOge's iBook.

lockley: voltage=12313 flags=4/0x004 amperage=1200 capacity=1431 current=1426 [99.7%]

17.6199 watt-hours on lockley's laptop.

Enkerli: voltage=12254 flags=4/0x004 amperage=1200 capacity=2882 current=2882 [100.0%]

35.316 watt-hours on Enerkli's iBook.

tamenti: voltage=11384 flags=4/0x004 amperage=1110 capacity=2054 current=1690 [82.3%]

23.3827 watt-hours on tamenti's iBook.

Joegrind: voltage=15817 flags=4/0x004 amperage=1019 capacity=6236 current=5593 [89.7%]

98.6348 watt-hours on JoeGrind's Powerbook. (Yeesh! That's off!)

xchanyazy: voltage=12442 flags=5/0x005 amperage=1200 capacity=3098 current=3089 [99.7%]

38.5453 watt-hours.

mattmoss: voltage=12389 flags=5/0x005 amperage=1200 capacity=1752 current=1746 [99.7%]

21.7055 watt-hours.

dcheng: voltage=12540 flags=5/0x005 amperage=1200 capacity=3645 current=3645 [100.0%]

45.7083 watt-hours.


[ Reply to This | # ]
Make sure you're looking at average voltage
Authored by: magitekkn on Mar 14, '03 02:31:39AM

The important thing to remember while performing this math is that your voltage drops off almost linearly (it appeared to begin to drop more rapidly towards the end for me) therefore you should take the mean value of the voltage across the entire discharge cycle to get the proper value.

Looking back over my numbers, my high voltage at 100% charge is 16.7v, whereas my minimum was 13.9v. If my battery was able to hold 16.7v for the entire discharge cycle (I've never seen a battery capable of this personally) and held a 3.5Ah capacity, the power capacity would be 58.45Wh (note this is a 55Wh battery). However, if the battery held at 13.9 for the entire discharge cycle, there would only be 48Wh.

Now if we take the average of 13.9 and 16.7 we get 15.3v. 15.3v by 3.5Ah = 53.55, still close to Apple's rating for a new battery.



[ Reply to This | # ]
Anyone here with 10.1
Authored by: jasenko on Mar 13, '03 09:32:46PM

Is anyone here with OSX 10.1? If not does anyone here have iBook or Powerbook as their second machine?
It would be really great to compare this results with someone who can install 10.1 and check batery info. I also noticed some 45 minutes drop after installing Jaguar for the first time. That can't be battery's fault. It must be something in the software.



[ Reply to This | # ]
Error
Authored by: momerath on Mar 13, '03 10:01:17PM

There is a small error in your description of one of the numbers.

mAh stands for milliampere-hours (the two are multiplied), so it is a measure of charge (3.6 Coulombs is equivalent to 1 mAh).



[ Reply to This | # ]
4 month old powerbook
Authored by: nxor on Mar 13, '03 10:02:04PM

My 4 month old powerbook (at 867mhz) which is mostly used as a desktop reports:

voltage=16676 flags=5/0x005 amperage=2 capacity=4149 current=4093 [98.7%]



[ Reply to This | # ]
My Late 2001 iBook 600 battery is sick...
Authored by: Xenex on Mar 14, '03 12:35:57AM

voltage=11198 flags=20/0x014 amperage=1091 capacity=555 current=154 [27.7%]

Ahem.

---
It's what's not there that makes what's there what it is.



[ Reply to This | # ]
My first rev TiBook is sicker still...
Authored by: semios on Mar 14, '03 07:35:40PM

voltage=15510 flags=4/0x004 amperage=988 capacity=488 current=427 [87.5%]

[sob] :(



[ Reply to This | # ]
Give your battery a thorough checkup
Authored by: yoyoman on Mar 14, '03 12:53:51AM

I tested two Powerbook batteries. One is from my 550Mhz, and the other is from a 667 (pre-DVI).

voltage=16588 flags=5/0x005 amperage=1200 capacity=3551 current=3550 [100.0%]
voltage=16084 flags=5/0x005 amperage=1200 capacity=3040 current=2888 [95.0%]

I don't remember which is which, but which ever one is from the 550Mhz Powerbook is just over 13 months old.



[ Reply to This | # ]
Week Old 1Ghz Powerbook
Authored by: richardjpratt on Mar 14, '03 01:08:05AM

voltage=16725 flags=5/0x005 amperage=77 capacity=4111 current=4067 [98.9%]

Haven't had any problems. Just posting this for general info. Amps seem low compared to others.... Ooops line above is from machine while plugged in. Below is running on battery.

voltage=16405 flags=4/0x004 amperage=376 capacity=4111 current=4053 [98.6%]

Does the flags= 4 vs. 5 mean its running from wall or not?

Rich



[ Reply to This | # ]
Discontinuities in charge profile
Authored by: VicF on Mar 14, '03 02:02:56AM

So, I used X-Charge to follow the charge profile of the battery in my GHz TiBook through a complete discharge and recharge cycle (nice little program, BTW). During the discharge cycle, my battery declined consistently until it got to about 15%, and then without warning, it plunked immediately down to 0%, forcing the PowerBook to sleep. I then plugged in, and the battery charged reasonably quickly to about 80%, at which point the rate of charge started to slow. It climbed quite slowly to about 86%, and then jumped immediately to 100% and (obviously) stopped charging.

So, what do these jumps down and up mean? Should this battery be recalibrated? Does resetting the PMU do that? (If I run the little bash script, I get "voltage=16751 flags=5/0x005 amperage=4 capacity=4096 current=4090 [99.9%]".)



[ Reply to This | # ]
Discontinuities in charge profile
Authored by: Winston on Mar 14, '03 07:57:52AM

LiIon batteries have a built in circuit that limits overcharging and run-down. Overcharging can cause the battery to overheat (i.e. catch fire) as well as damaging it. Running it down too far also can cause charging problems. Maybe what you are seeing is caused by the protection circuit.

Apparently the protection circuits cause a lot of problems tooccur with "good" LiIons, for example an undercharge circuit that kicks in and won't let the battery charge.

Also, LiIons degrade over time whether you use them or not.

More info on all battery types here:
http://www.buchmann.ca

summary on LiIons here:
http://dealmac.com/forums/read.html?f=1&i=1092115&t=1092077



[ Reply to This | # ]
PowerBook G4 867 Mhz (12 inch)
Authored by: ptb@mac.com on Mar 15, '03 11:45:47AM

It is currently recharging after an unplugged-fest this morning, but this is my PowerBook G4 (12 inch).

voltage=12687 flags=7/0x007 amperage=1200 capacity=4495 current=3724 [82.8%]

- ptb



[ Reply to This | # ]
my results
Authored by: rgray on Mar 15, '03 12:12:09PM

voltage=16571 flags=5/0x005 amperage=1200 capacity=1310 current=1310 [100.0%]
voltage=15043 flags=4/0x004 amperage=856 capacity=1310 current=792 [60.5%]
voltage=14564 flags=4/0x004 amperage=1185 capacity=1310 current=605 [46.2%]

On an original Ti400 original battery... What _should_ the capacity be? Obviously it is time to take my Applecare for a walkies.... ;-}



[ Reply to This | # ]
CALL 1-800-APL CARE and report problems
Authored by: reinmund on Mar 15, '03 03:28:03PM

Apparently, for many users, neither resetting PMU, nor resetting PRAM, nor re-installing OS 10.2.4 nor going back to an earlier OS version will fix the problem. Most likely, the battery is being physically killed.

I talked to Apple Support on the phone. They collected all the data and information, but said, that this is supposedly the first time (haha) that anyone reported the problem. Well, whoever believes that.

Right now, the Apple Support guy thinks it's just my old battery dying. They advised me to buy a new battery, try how the new battery does and if there is any problems, return the battery. This would be proofing that it is not a battery problem.

So, what can be done ?
I think, the best way to get it fixed AND to get a new battery is doing the following:

YOU ALL SHOULD CALL APPLE SUPPORT AND REPORT YOUR PROBLEMS.

Every caller will increase the awareness and likelihood that Apple will actually acknowledge the problem as being causeb by faulty software and replace batteries for free!



[ Reply to This | # ]
CALL 1-800-APL CARE and report problems
Authored by: applepenguin on Mar 15, '03 09:02:35PM

I have an iBook 700, and my battery failed, but I don't think it was software related.

you know the 4 little lights on the bottom of the battery that display the charge? Well, I guess my battery "crashed" or something, because the first light was just staying on, whether it was in or out of the iBook, plugged in or not. I called AppleCare about this, and they shipped me a new one right way (via Airborne Express!)

i don't know if it was before or after I updated to 10.2.4 or not.



[ Reply to This | # ]
ibook stats & some ramblins
Authored by: zarqman on Mar 17, '03 01:49:04AM

ibook 700 12" 16vram from aug 02

voltage=12427 flags=5/0x005 amperage=1200 capacity=2366 current=2328 [98.4%]

somewhere in the late jan/early feb 03 timeframe i was still able to get 4 hours with a low screen brightness setting (last time i remember actually checking until recently). now i can get about 2:20 at the same setting. 10.2.4 does seem to have had a negative effect on things, although not as strongly as some have reported.

just a couple of days ago i also experienced an anomaly that was a first, and so far only. the machine was on battery, heading down, although i don't know exactly how low as i don't usually pay attention, instead waiting for the standard warning when it drops under 10min of time. instead, i did not get the warning and the machine actually powered off. not standby, but off. i reset the pmu after that and have gotten the normal warning since (although i don't know if resetting the pmu helped or not).

i guess i'll also note that i have had a number of power-related issues with this machine. which, in all honestly, are the only thing i can find wrong with it. i have had 3 lockups resuming from standby. however, more importantly, the original battery was doa. wouldn't charge at all; single led stayed lit all the time, whether plugged in or not, whether battery was in machine or not. apple, of course, replaced it. then, a couple months ago something fried and the backlight on my screen went out. apple repaired it and on the return paperwork said something that seemed to indicate the power supply had been replaced. don't know if that's coincidence or indicative of broader power-related issues.



[ Reply to This | # ]
capacity lowers when battery drained ?
Authored by: cynikal on Mar 19, '03 12:15:44AM

in an effort to keep myself from staying up too late when i already get home late from work, i decided to not use my power adapter so i would be forced to go to sleep when the battery ran out..

well i checked the battery before it ran out and after and i saw that my overall capacity lowered when i was re-charging the next day.. (ok i caved in and recharged it right after anyway)..

here's how it was before on its way down..

voltage=14293 flags=4/0x004 amperage=1670 capacity=4252 current=1021 [24.0%]
voltage=14037 flags=4/0x004 amperage=1987 capacity=4252 current=371 [8.7%]
voltage=13802 flags=404/0x194 amperage=1832 capacity=4252 current=121 [2.8%]

then i plugged it in and it started charging up and saw this..

voltage=14489 flags=389/0x185 amperage=1584 capacity=4195 current=6 [0.1%]
voltage=14862 flags=391/0x187 amperage=1206 capacity=4195 current=16 [0.4%]
voltage=15490 flags=7/0x007 amperage=1200 capacity=4195 current=908 [21.6%]

but no matter what (even when it got fully charged again), my capacity hasn't gone back to 4252 and is only at 4195..

so does this mean it's bad for your battery to run it down all the way and charge it back up?



[ Reply to This | # ]
Bad battery or bad PMU?
Authored by: pruritis ani on Mar 19, '03 10:35:45PM

Another report:

My battery life dropped from >4 hours to around 30 minutes when I upgraded to Jaguar 10.2 from 10.1.5. Since then it has taken a serious turn for the worse, as is evidenced by the tests with this script over time. Moreover, this script gives me a capacity approximately TEN TIMES higher than what everyone here has reported, even though I only get around 8 minutes before it drops much.

Prior to unplugging:
Time ~0:00:00: voltage=15978 flags=5/0x005 amperage=1200 capacity=64239 current=64033 [99.7%]

After unplugging at
Time 0:05.49: voltage=15641 flags=4/0x004 amperage=1112 capacity=64239 current=64027 [99.7%]
Time 7:39.96: voltage=14181 flags=4/0x004 amperage=1161 capacity=64239 current=5016 [7.8%]
Time 8:11.89: voltage=14181 flags=4/0x004 amperage=1290 capacity=64239 current=2007 [3.1%]

Plugged battery back in after 8:58 minutes
Time 08:58.44: voltage=16309 flags=135/0x087 amperage=1269 capacity=63983 current=2017 [3.2%]
Time 13:37.62: voltage=16403 flags=135/0x087 amperage=1200 capacity=63983 current=2101 [3.3%]
Time 17:37.12: voltage=16446 flags=135/0x087 amperage=1200 capacity=63983 current=2160 [3.4%]
Time 25:50.02: voltage=16495 flags=135/0x087 amperage=1200 capacity=63983 current=2258 [3.5%]
Time 33:18.46: voltage=16532 flags=135/0x087 amperage=1200 capacity=63983 current=2327 [3.6%]


Interestingly, even when the powerbook completely shuts down after running out of power, ALL FOUR LIGHTS on the battery light up! Anyone have any ideas?



[ Reply to This | # ]
Ignore battery for two weeks, capacity returns!?
Authored by: peterw on Mar 26, '03 10:21:59PM

My May 2001 ibook running 10.2.4 was getting only a bit more than a half hour of run time. (airport off, screen set low, no cd use, 640ram).

This reading of 1240 capacity was about 2-3 weeks ago:
voltage=12559 flags=7/0x007 amperage=1200 capacity=1240 current=1228 [99.0%]

I just got an emac, have barely touched the ibook in the last two weeks. Turned it on, and the battery was totally dead. Check out the greatly improved capacity of 3800:
voltage=11836 flags=7/0x007 amperage=1200 capacity=3800 current=1239 [32.6%]

It's still charging (now up to 71%) and its still reporting the 3800 capacity.

Charging is proceeding smoothly and taking forever, so it seems like I do have the increased capacity. I of course haven't tried to use the battery yet Hmmm....



[ Reply to This | # ]
Strange flags...
Authored by: englabenny on Apr 15, '03 02:14:29PM
Is there a reference for the flags? My battery has reported some very strange flags recently.... what does this mean?:
voltage=16179 flags=838860807/0x32000007 amperage=1200 capacity=2277 current=534 [23.5%]
I am currently charging, but the flags always show up, whatever the last/first flag is (the 0x7 right now)
And yes, my powerbook G4 has gone through some years...(two? hm..)

[ Reply to This | # ]
Strange flags...
Authored by: elmer-12 on Apr 25, '03 11:53:07AM

I have a two month old 12-inch powerbook, and I have been seeing the exact same flags when I am plugged in. I did not used to have weird flags. I have a log of this script that shows I did not have these flags when plugged in at least until after April 3rd. Sometime between April 3rd and April 21st this started happening.



[ Reply to This | # ]
Strange flags...
Authored by: elmer-12 on Apr 25, '03 11:56:15AM

Could this be 10.2.5 do you think?



[ Reply to This | # ]
Strange flags...
Authored by: englabenny on Apr 25, '03 12:22:27PM

yes, It must be.... when this hint was posted, i started a cron job to create a log for me to see how my battery is losing power. Checking the log shows this change happened right after the 10.2.5 upgrade restart. Still wonder what they mean, though...



[ Reply to This | # ]
Give your battery a thorough checkup
Authored by: Gabe462 on Sep 28, '03 10:14:50PM

'Scuse me for being somewhat of a unix newbie, but how do I run this script? I know how to write C programs, but I don't know the difference between programs and scripts. (?)

Gabe



[ Reply to This | # ]
Give your battery a thorough checkup
Authored by: t3hl33t on Jan 26, '05 05:43:07AM

Copy and paste it into Terminal. Hit Enter.



[ Reply to This | # ]
Give your battery a thorough checkup
Authored by: rasda on Dec 19, '03 12:31:46PM

i have a pismo 400 for 2 and a half years. my first battery drains in the guarantee time so i got a new one which was very fast drained out too. i don't know why. a friend of mine has the same pismo and his battery is still cool. he bought it before mine. he has another power supply. it has the same form but shorter cables. maybe my power supply is not working correctly cause i get strange numbers when i run the script with power supply connected.

here with power supply:
capacity=197 amperage=1272 current=0 voltage=12154 flags=0/0x000 capacity=10000 amperage=1200 current=0 voltage=0 flags=838860931 [6901933.0%]

and here without:
capacity=197 amperage=1200 current=197 voltage=12398 flags=0/0x000 capacity=10000 amperage=1200 current=0 voltage=0 flags=32 [0.0%]

i will try the power supply of my friend.

cheers
rasda



[ Reply to This | # ]
battery script
Authored by: sjk on Dec 19, '03 10:32:56PM
Looks like you're running a Jaguar script on Panther. You can get a fancier zsh script that works on Panther from http://www.mitt-eget.com/software/macosx/ (which was mentioned earlier in this hint). Output on my iBook 600:

% battery
Battery 1
  Battery:  battery installed, above warning level
  Charger:  charger connected, not charging
  UPS:      UPS not installed
  Voltage:  12.312V
  Current:  1.200A (approx 1:27)
  Capacity: 1.756Ah of 1.756Ah (100.0%)
Before installing Apple's recent battery update and recalibrating the capacity was something like 1.056Ah so there's some improvement but if it doesn't get any higher I'll probably end up replacing the battery. I only get about 1.5 hours usage with minimum screen brightness.

[ Reply to This | # ]
Give your battery a thorough checkup
Authored by: turtlebud on Nov 02, '04 12:32:47PM

I'm getting the following when I run the battery check script

>battery_check
capacity=3653 amperage=1200 current=3633 voltage=15977 flags=0/0x000 [0.0%]

Am I doing something wrong?

I am running OS 10.3.5 on a 1 Ghz Tibook on battery power.



[ Reply to This | # ]