I’m trying to build a script to run when my iBook’s cable is unplugged and it switches to battery power. How can I do this?
Hi,
you can detect whether a power supply is connected or not with this:
set BattInfo to do shell script "ioreg -l | grep IOBatteryInfo"
set TID to text item delimiters
set text item delimiters to {"\"Flags\"="}
set b to text item 2 of BattInfo
set text item delimiters to TID
set Flag to text 1 thru ((offset of "," in b) - 1) of b
--> 4 (if unplugged)
Hi Jamie,
They changed the pmset unix command in Tiger, but I think you can use that. Do you have different settings in the energy saver preferences for battery/adapter processor performance? Mine is highest for power adapter and automatic for battery power.
gl,
Hi kel,
thanks, pmset makes it much easier to detect which kind of power is used
set Power to word 1 of (do shell script "pmset -g |grep '*'") --> AC or Battery
Thanks, sorry I haven’t checked back in a while. I was hoping there was a way I could have it run without needing a stay-open app. Do you think there is a way?
I’ve just added this check to OmniGrowl 1.2, which will be posted shortly. (Thanks StefanK)