-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbattery.sh
executable file
·82 lines (68 loc) · 2.37 KB
/
battery.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh
stats=`ioreg -f -r -c AppleSmartBattery \
|tr ',' '\n' \
|sed -E 's/^ *//g'`
currcharge=`echo $stats \
|sed -E -e 's/.*"AppleRawCurrentCapacity" = ([0-9]*).*/\1/g'`
echo "Current charge "$currcharge" mAh"
maxcapacity=`echo $stats \
|sed -E -e 's/.*"AppleRawMaxCapacity" = ([0-9]*).*/\1/g'`
echo "Full charge capacity "$maxcapacity" mAh"
echo "Charge at "`echo "scale=3;"$currcharge"/"$maxcapacity"*100" |bc -l`"% capacity"
designcapacity=`echo $stats \
|sed -E -e 's/.*"DesignCapacity" = ([0-9]*).*/\1/g'`
echo "Design capacity "$designcapacity" mAh"
echo "Current full charge at "`echo "scale=3;"$maxcapacity"/"$designcapacity"*100" |bc -l`"% design capacity"
cycles=`echo $stats \
|sed -E -e 's/.*"CycleCount" = ([0-9]+).*/\1/g'`
echo "Cycle count is "$cycles
ktemp=`echo $stats \
|sed -E -e 's/.*"Temperature" = ([0-9]+).*/\1/g'`
echo "Battery temperature "`echo "scale=2;("$ktemp"/10-273.15)*(9/5)+32" |bc -l`" °F ("`echo "scale=2;("$ktemp"/10-273.15)" |bc -l`" °C)"
watts=`echo $stats \
|sed -E -e 's/.*"Watts"=([0-9]+).*/\1/'`
if echo $stats |egrep -q "Watts"; then
echo "Power adapter at "$watts" Watts"
fi
amps=`echo $stats \
|sed -E -e 's/.*"InstantAmperage" = ([0-9]*).*/\1/g' \
|bitwise -od -wd`
echo Instant Amperage $amps mA
if [ $amps -ge 0 ]; then
if [ $amps -eq 0 ]; then
charging=`echo "Connected at "`
else
charging=`echo "Charging with "`
fi
else
charging=`echo "Discharging with "`
fi
millivolts=`echo $stats \
|sed -E -e 's/.*"AppleRawBatteryVoltage" = ([0-9]*).*/\1/g'`
volts=`echo "scale=2;$millivolts/1000" |bc -l`
echo "Battery voltage "$volts" V"
echo $charging `echo "scale=3;("$volts" * "$amps")/1000" \
|bc -l \
|sed -E -e 's/.*/& Watts/'`
famcode=`echo $stats |sed -E -e 's/.*"FamilyCode"=([0-9]+).*/\1/' |bitwise -ww -od`
if [ $famcode -ne 0 ]; then
echo "Power adapter connected"
else
echo "Power adapter disconnected"
fi
currentcapacity=`echo $stats \
|sed -E -e 's/.*"CurrentCapacity" = ([0-9]*).*/\1/g'`
echo "Current capacity "$currentcapacity"%"
stateofcharge=`echo $stats \
|sed -E -e 's/.*"StateOfCharge"=([0-9]*).*/\1/g'`
echo "State of charge "$stateofcharge"%"
if [ $amps -lt 0 ]; then
remh=` echo "($currcharge/$amps)*-1" |bc -l`
remih=`echo "scale=0;$remh/1" |bc`
remmin=`echo "scale=0;(($remh-$remih+0.005)*60)/1" |bc `
if [ $remmin -lt 10 ]; then
echo Time Remaining $remih:0$remmin
else
echo Time Remaining $remih:$remmin
fi
fi