|
|
#1 |
|
Prospect
Join Date: May 2009
Posts: 4
|
Is it possible to trigger an Applescript when the battery reaches a low (~20%) level? or when the low battery warning pops up?
Could you have a script running in the background that looks at the output of Code:
ioreg -wO -l | grep Capacity |
|
|
|
|
|
#2 |
|
Site Admin
Join Date: Jan 2002
Location: Montreal
Posts: 31,938
|
Yes you could.
__________________
hayne.net/macosx.html |
|
|
|
|
|
#3 |
|
Prospect
Join Date: May 2009
Posts: 4
|
Haynes, thanks for confirming my suspicions!
I found this old perl script which checks the battery level and calls an Applescript: http://www.zaftig.net/node/322 (code listing ) But it's doesn't work in Leopard, the options for ioreg and the output format are different: Code:
/usr/sbin/ioreg -p IODeviceTree -n "battery" -w Code:
"IOBatteryInfo" = ({"Voltage"=11925,"Flags"=4,"Amperage"=1705,"Capacity"=4149,"Current"=3717})
Code:
ioreg -wO -l | grep Capacity Code:
"LegacyBatteryInfo" = {"Capacity"=4149,"Voltage"=11925,"Flags"=4,"Current"=3717,"Amperage"=1705,"Cycle Count"=123}
Any help would be appreciated! |
|
|
|
|
|
#4 |
|
Hall of Famer
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,945
|
Something like this will extract the current percentage:
set Cap to (do shell script "ioreg -wO -l | grep Capacity")
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3 |
|
|
|
|
|
#5 |
|
Prospect
Join Date: May 2009
Posts: 4
|
Thanks, NovaScotian. That's a lot more simple!
|
|
|
|
![]() |
| Tags |
| applescript, battery |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|