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

Make a more obvious low battery warning Laptop Macs
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
else
 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"
  pause
 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" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
 <key>KeepAlive</key>
 <false/>
 <key>Label</key>
 <string>batteryAlert</string>
 <key>LowPriorityIO</key>
 <true/>
 <key>ProgramArguments</key>
 <array>
  <string>/usr/bin/osascript</string>
  <string>/etc/batteryScript.applescript</string>
 </array>
 <key>RunAtLoad</key>
 <true/>
 <key>ServiceDescription</key>
 <string>Battery Alert</string>
 <key>StartInterval</key>
 <integer>30</integer>
</dict>
</plist>
That's all! Reboot and enjoy.

[crarko adds: I haven't tested this one. Zarvox? That will get your attention, all right.]
    •    
  • Currently 3.90 / 5
  You rated: 1 / 5 (10 votes cast)
 
[11,866 views]  

Make a more obvious low battery warning | 14 comments | Create New Account
Click here to return to the 'Make a more obvious low battery warning' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Make a more obvious low battery warning
Authored by: Levito on Feb 23, '11 08:21:18AM

Strange script. It assumes you're playing iTunes music. If you're not it, starts up iTunes. If you're listening to music from another app (VLC perhaps), it will blow out your eardrums when the volume is set to 100.
Why not do something like invert the colors of the screen for 5 seconds, then invert them back?



[ Reply to This | # ]
Make a more obvious low battery warning
Authored by: Toggi3 on Feb 25, '11 02:04:03AM

I wanted something to let me know in earshot of the computer, not necessarily when I was at it. I generally have itunes open all the time, so this works for me. Improvements/changes/suggestions are most welcome.

I like your idea to make the screen flash inverted very much, how would you do this in applescript?



[ Reply to This | # ]
Make a more obvious low battery warning
Authored by: Levito on Feb 25, '11 06:44:29AM
Yea, I get it, a lot of the custom scripts are just that-- custom. Doesn't work for everyone, but gives people a good idea of what's possible. For inverting colors on the screen, check this post

[ Reply to This | # ]
Make a more obvious low battery warning
Authored by: prichardson on Feb 23, '11 08:59:22AM
You can skip the rebooting part if you manually load the launchd module.

launchctl load ~/Library/LaunchAgents/batteryAlert.plist


[ Reply to This | # ]
Make a more obvious low battery warning
Authored by: una on Feb 23, '11 11:08:00AM
I can't get it to work.. I did like you said prichardson, but this is what I get:
launchctl: no plist was returned for: /Users/aurimasdapkunas/Library/LaunchAgents/batteryAlert.plist
launchctl: no plist was returned for: /Users/aurimasdapkunas/Library/LaunchAgents/batteryAlert.plist 
nothing found to load
Also after restarting laptop there is no changes.

[ Reply to This | # ]
Make a more obvious low battery warning
Authored by: blgrace on Feb 23, '11 01:48:50PM

just thought it worth mentioning that you can navigate easily to any of the "hidden" directories in the save dialog box by typing Command Shift G and then typing in your path.



[ Reply to This | # ]
Make a more obvious low battery warning
Authored by: mrboma on Feb 23, '11 02:51:49PM

I have the OS flash the screen and speak all warnings. System Prefs/Universal Access for screen flash; System Prefs/Speech for spoken warning dialogs. I put a 4 second delay on speech so that it only speaks if I ignore a warning for 4 seconds.



[ Reply to This | # ]
Make a more obvious low battery warning
Authored by: BobHarris on Feb 24, '11 05:45:44PM

I personally like Unplugged (free download)
<http://www.macupdate.com/info.php/id/21158/unplugged>

It is even nicer with Growl, as I arrange for a bright orange for unplugged notices that stay on the screen until dismissed, and use a green alert that goes away after about 10 seconds when power is plugged in.



[ Reply to This | # ]
Make a more obvious low battery warning
Authored by: Anonymous on Feb 28, '11 12:06:34PM
Unplugged with SoundForGrowl. Looks good.

[ Reply to This | # ]
Make a more obvious low battery warning
Authored by: mark hunte on Feb 26, '11 05:55:06AM
You can play sounds headless (no GUI app) and its always a good idea to return the volume to its last setting.

This is a small example. Which gets the current volume level, gets the duration of the file
(best use a short file, I have a short feed back loop) plays the file over the output sound and delays
(pauses before any more commands in the script) for the duration of the sound file, and then returns the volume back to its original level.

You can add to it a check to see if certain apps like iTunes is running (look at application processes running), which will not open iTunes if it is not open already.
But I do not have time to day to add that. It simple and there should be lots of examples out there. The example:



property mySound : "/Users/USERNAME/Music/Other/shortFeedBackLoopmp3" -- Path to sound file 


 
on run
	-- get current  sound volume
	set av to output volume of (get volume settings)
	set volume output volume 100
	-- go to play  sound file
	set_system_sound() -- set new sound
	
	--return to original sound
	set volume output volume av
	
end run

on set_system_sound()
	-- get the duration of the sound file
	set timer to last word of (do shell script "mdls -name kMDItemDurationSeconds " & quoted form of mySound) as number
	
	-- go to play  sound file
	do shell script "afplay " & quoted form of mySound & " > /dev/null 2>&1 &"
	delay timer
end set_system_sound 
---
mh


[ Reply to This | # ]
Make a more obvious low battery warning
Authored by: Anonymous on Feb 28, '11 12:01:54PM

/etc is a weird place for a script. This is generally used for settings. There are some scripts under /etc, but these generate settings, or are part of the system boot sequence (which is in itself a type of setting). A better place for a script like this would be /usr/local/bin.

Generally in the Unix world, /etc is for settings; /usr is used for installed applications and scripts; /opt for third party alternatives to the OS vendor's shipped environment (which is why MacPorts lives there); and the /usr/local and /opt/local areas are for things unique to a particular environment. If it belongs to a particular user on a system, it should live under their home directory; for scripts, that's preferably $HOME/bin.

Hope that helps.



[ Reply to This | # ]
Make a more obvious low battery warning
Authored by: asmeurer on Mar 17, '11 08:45:28PM
I would recommend installing SlimBatteryMonitor . Not only does it give you a much better battery menu item with fined tuned options (you can choose, for example, to show only the percentage when changing and the time remaining when unplugged), it also gives a very nice warning when your battery is critically low (it's a very large dialog that appears on top of everything).

[ Reply to This | # ]
Make a more obvious low battery warning
Authored by: imyque on Nov 17, '11 04:16:17AM

Hi,

Thank you Toggi3 for this great work. And thanks to Prichardson and Mark Hunte, whose tips helped me to improve on the original Apple script.

You will need to set your intervals to about 300 at least

Improvements
1. Two warning levels, LOW and CRITICAL
2. When battery is low, the system volume fades out and iTunes stops and then u hear the alert twice and volume fades back in. Except the system volume was muted before the script started executing.
3. When critical, iTunes stops and u hear a 60secs count down.
4. If you plug in to power, then the script stops, or else it proceeds to Sleep
5. The system volume is reset to the original level before the script began executing

God Bless You all.

[--------------code------------------]

--- Sub Routines ---

-- Restore Volume
to restoreVolume(sysVolume, isMuted)

if isMuted then
set volume output muted isMuted
else
set volume output volume round (sysVolume * 0.8)
end if

end restoreVolume

-- Check wether on AC Power
to checkOnACPower(sysVolume, isMuted)
--Checking if Mac is on AC Power
set Cap to (do shell script "ioreg -w0 -l | grep ExternalChargeCapable")
tell Cap to set {wallPower} to {last word of paragraph 1}

-- If Yes, Thank the user, restore Volume and Itunes, and Quit
if wallPower = "Yes" then
beep 5
say "THANK YOU!"
delay 2
say "You saved my life"

--log "System Volume" & sysVolume
restoreVolume(sysVolume, isMuted)


tell application "iTunes"
play
end tell

return true
else
return false
end if
end checkOnACPower


--- Main Routine ---

--Checking if Mac is on AC Power
set Cap to (do shell script "ioreg -w0 -l | grep ExternalChargeCapable")
tell Cap to set {wallPower} to {last word of paragraph 1}

-- If Yes, then exit script
if wallPower = "Yes" then
return 0

else -- Get to work!

-- Get Battery level
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)

-- Get System Volume Level and Mute Status
set sysVolume to output volume of (get volume settings)
set isMuted to output muted of (get volume settings)

-- If Battery Level is CRITICAL?
if Pct &#8804; 15 then

tell application "iTunes"
pause
end tell

set volume alert volume 70
set volume 100

beep 5
say "PLUG ME to a power source now! Or else..."

beep 15
say "Cow bell IS LEAVING THE BUILDING in sixty seconds!" -- using "Zarvox"
delay 10
if checkOnACPower(sysVolume, isMuted) then return 0
say "Cow bell IS LEAVING THE BUILDING in fifty seconds!" -- using "Zarvox"
delay 10
if checkOnACPower(sysVolume, isMuted) then return 0
say "Cow bell IS LEAVING THE BUILDING in forty seconds!" -- using "Zarvox"
delay 10
if checkOnACPower(sysVolume, isMuted) then return 0
say "Cow bell IS LEAVING THE BUILDING in thirty seconds!" using "Zarvox"
delay 10
if checkOnACPower(sysVolume, isMuted) then return 0
say "Cow bell IS LEAVING THE BUILDING in twenty seconds!" using "Zarvox"
delay 10
if checkOnACPower(sysVolume, isMuted) then return 0
say "Cow bell has left THE BUILDING!"
delay 10
if checkOnACPower(sysVolume, isMuted) then return 0
------- I Was...
--say "GARFIELD IS LEAVING THE BUILDING in 10 seconds!" using "Zarvox"
-- set temp to display dialog "GARFIELD is Leaving the Building in 10 Seconds!" buttons {"Hold It Right There", "Leave Now"} default button 1 giving up after 10
--set response to button returned of temp

-- If User asks for more time...then
--if response is equal to "Hold It Right There" then
-- beep 2
-- display dialog "You have 60 more Seconds Save Your Work!" buttons {"OK"} default button 1 giving up after 10
--delay 90
--set volume output volume round (sysVolume * 0.8)
--tell application "System Events"
-- sleep
--end tell
--end if
----------

-- User doesn't care, so go to Sleep
say "I repeat. Cow bell has left THE BUILDING!" using "Zarvox"
delay 2

beep 5
restoreVolume(sysVolume, isMuted)

tell application "System Events"
sleep
end tell

else if Pct &#8804; 30 then -- If Battery Level is LOW?

if not isMuted then
set volume output volume round (sysVolume * 0.8)
delay 2
set volume output volume round (sysVolume * 0.6)
delay 2
set volume output volume round (sysVolume * 0.4)
delay 2
set volume output volume round (sysVolume * 0.2)
delay 2
set volume output volume round (sysVolume * 0)
end if

tell application "iTunes"
pause
end tell
set volume alert volume 70
set volume 100
beep 15
say "LOW BATTERY "
beep 5
delay 10
-- display dialog "Your Battery capacity is below 25%, Start rounding up!" buttons {"OK"} default button 1 giving up after 10
beep 5
say "LOW BATTERY " using "Zarvox"

delay 5
set volume output volume round (sysVolume * 0)

tell application "iTunes"
play
end tell

if not isMuted then
set volume output volume round (sysVolume * 0.2)
delay 2
set volume output volume round (sysVolume * 0.4)
delay 2
set volume output volume round (sysVolume * 0.6)
delay 2
set volume output volume round (sysVolume * 0.8)
else
set volume output muted isMuted
end if
--delay 180

end if


end if
[-------------/code-------------]




[ Reply to This | # ]
Make a more obvious low battery warning
Authored by: jpd3K on Dec 18, '11 05:39:10PM

Sorry - I realize this is sort of unrelated: Before a recent hard drive replacement, I had set up my low battery warning to read randomly from a set of texts that I created (I thought the lines from Radiohead's, "Fitter, Happier" were appropriate), but now I don't remember how I did it, nor can I find the instructions online anymore. (I'm pretty sure I initially did this in 10.5, but it stuck around after upgrading to 10.6.) Any help would be much appreciated!



[ Reply to This | # ]