Make a more obvious low battery warning

Feb 23, '11 07:30:00AM

Contributed by: Toggi3

I once owned a ThinkPad T60 series and when the battery in it became critically low it would beep wildly and make its low battery status very well known (impossible to ignore) and forced me to do something about it.

I am distracted easily, and when focused on other things, I tend to completely ignore that little warning window and the tiny alert noise that comes with it that Mac OS X presents me when my battery is low. I have created an AppleScript and developed a method to get a similar effect on my Mac laptop.

Paste the following contents into the AppleScript Editor and save the script to: /etc/batteryScript.applescript. [crarko adds: You may first need to save the file to your Desktop and then copy it to the hidden /etc directory after using the Finder 'Go to Folder...' command.]

set Cap to (do shell script "ioreg -w0 -l | grep ExternalChargeCapable")
tell Cap to set {wallPower} to {last word of paragraph 1}
if wallPower = "Yes" then
 return 0
 set Cap to (do shell script "ioreg -wO -l | grep Capacity")
 tell Cap to set {Available, Max} to {last word of paragraph 2, last word of paragraph 1}
 set Pct to round (100 * Available / Max)

 if Pct <= 4 then
 tell application "iTunes"
 end tell
 set volume 100
 do shell script "say -v \"Zarvox\" \"LOW BATTERY\" "
 if Pct <= 3 then
  beep 5
  do shell script "say -v \"Zarvox\" \"PLUG ME IN NOW\""
 end if
 end if
end if
Then perform this command using the Terminal:

sudo chmod +rx /etc/batteryScript.applescript

Create a new text file and paste the following contents into it. Save this file as ~/Library/LaunchAgents/batteryAlert.plist.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
 <string>Battery Alert</string>
That's all! Reboot and enjoy.

[crarko adds: I haven't tested this one. Zarvox? That will get your attention, all right.]

Comments (14)

Mac OS X Hints