Re: Getting battery state?
Re: Getting battery state?
- Subject: Re: Getting battery state?
- From: Giuliano Gavazzi <email@hidden>
- Date: Mon, 17 Mar 2003 08:44:50 +0000
At 0:28 +0100 2003/03/17, Jakob Peterhdnsel wrote:
Hi List.
Is it possible to get the state of the battery on a iBook/PowerBook?
Either directly in AS, or via do shell script...
I found this sometime ago, I do not remember where:
#!/bin/bash
[ -x /usr/sbin/ioreg ] && \
/usr/sbin/ioreg -p IODeviceTree -n "battery" -w 0 | \
sed -ne '/| *{/,/| *}/ {
s/^[ |]*//g
/^[{}]/!p
}' | \
awk '/Battery/ {
gsub("[{}()\"]","", $3)
gsub(","," ",$3)
split($3,ct," ")
# extract flag value and convert to hex
sub("Flags=","",ct[2])
str=sprintf("Flags=%d/0xx",ct[2],ct[2])
sub("Flags=[0-9]*",str,$3)
# get max and current charge levels
sub(".*=","",ct[4])
sub(".*=","",ct[5])
printf("%s [%.1f%%]\n",tolower($3),100*ct[5]/ct[4])
}'
# EOF
./battery.sh
voltage=14689 flags=4/0x004 amperage=1122 capacity=2329 current=1069 [45.9%]
current is the present capacity in absolute value and percentage.
Giuliano
--
H U M P H
|| |||
software
Java & C++ Server/Client/Human Interface applications on MacOS - MacOS X
http://www.humph.com/
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.