Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- log "BatteryMonitor: Launching..."
- set theCounter to 60
- set theInterval to 2
- set okBtnText to "Go Ahead!"
- set Pct to 100
- set minBattLvl to 20 -- Min Battery Lvl
- repeat until theCounter is 0
- 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)
- end if
- if Pct > minBattLvl then
- return 0
- end if
- tell me to activate
- set usrResponse to display dialog ¬
- "Battery below min safe level of " & minBattLvl & "%.
- Forcing sleep in: " & theCounter & ¬
- " seconds" as text buttons {"Cancel", okBtnText} ¬
- default button ¬
- okBtnText with icon caution with title ¬
- "WARNING: Battery Monitor" giving up after theInterval
- if button returned of usrResponse is "Cancel" then
- return 0
- end if
- if button returned of usrResponse is okBtnText then
- exit repeat
- end if
- -- delay 5
- set theCounter to theCounter - theInterval
- end repeat
- -- Log entry in syslog
- do shell script "logger 'BatteryMonitor: Battery level low below " & minBattLvl & "%, forcing sleep...'"
- -- Hybernate/Sleep command
- do shell script "pmset sleepnow"
- -- DEBUG display dialog "Here we sleep..."
- -- Delay exit for allow for sleep/wake
- delay 30
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement