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


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: 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 ≤ 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 ≤ 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 | # ]