You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Scripting with battery info - or other options

I've noticed that one of my favorite features of the PPC Macs is not present on Intel. If the battery gets too low, with the PPC Macs, the machine would enter sleep mode, allowing you to save what you were doing by getting to external power before the battery dies. On Intel, the machine just turns off when the battery gets too low to keep running.

Is there a way to enable this feature, or do I need to write a script?

If I have to write a script, I have figured out basically how to do it. I just have one question. How can my script determine the battery level? I want to have a launchd task check the battery every few minutes. If it gets too low, it will execute a command line program called deepsleep which will write the RAM to disk and shut down the system. The script can be in bash or Applescript, which ever is easier to determine the battery level with.

I have looked all over the IORegistry with no success. Am I missing something? Has apm been ported from Linux to Mac? I know that would do what I want.

Macbook Core Duo, Mac OS X (10.4.8), 2GB RAM, 120GB HD, SD

Posted on Nov 9, 2006 12:53 PM

Reply
4 replies

Nov 9, 2006 5:53 PM in response to Robert Grimm

I guess I'll answer part of my question. I found the source to a widget called Juice. I read the parts related to finding battery status and am beginning to write a script to put the machine into safe sleep when it gets low. I would still like to hear from anyone who knows if I need to finish this script or if the OS has a feature that can do this.

I don't mean changing the hibernate mode while on battery. I still want normal sleep to work when I put it to sleep.

Nov 9, 2006 6:11 PM in response to Robert Grimm

Sorry to keep commenting on my own comments.

It occurred to me that I should post my solution. It wouldn't let me edit my last comment, so I had to make another.

The solution is to use `ioreg -n AppleSmartBattery -w0 -x | grep CurrentCapacity | cut -d ' ' -f 19` and the same thing again with Max in place of Current. That will give you two hex numbers. Divide the first one by the second one and you will have the battery charge as a percentage.

Message was edited by: Robert Grimm

Nov 9, 2006 6:54 PM in response to Robert Grimm

On my C2D MBP when there is not enough battery for sleep, it goes to safe sleep. So when the battery is like 5% I get the message with "save your work..." and then the computer just shuts-off. But actually is goes in safe sleep, because when I connect the power and turn it on again, it's exactly like before shut-off, and it starts slower than sleep, with the little bars .... safe sleep (hibernation).

Nov 10, 2006 10:59 PM in response to marianmi

It sounds like my problem is a case of early adopter syndrome. They must have fixed it in the second generation. That sounds like the way I was expecting it to work.

I would like to know how that works, if anyone has any insight into this. From poking around in the power .plists and the IO Registry, it doesn't look like there can be two hibernation modes active at once on any given profile. Is there a daemon that changes the hibernate mode on the battery profile based on battery level? If so, is the source available so it can be ported to first gen Intel machines?

I'm currently entering safe sleep mode through a script running as a system agent every 120 seconds, but it polls the hard drive too frequently, so it prevents normal sleep from working.

Scripting with battery info - or other options

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.