12

This simply displays the time left on your battery. If it's fully charged it'll display "~" and otherwise it'll display the time left until fully charged (if plugged in) or the time left until fully drained (if it's unplugged).

Script:

isFullyCharged=`ioreg -n AppleSmartBattery | grep FullyCharged | awk '{ print $5 }'`
timeLeft=`ioreg -n AppleSmartBattery | grep TimeRemaining | awk '{ print $5 }'`

if [ $isFullyCharged = "Yes" ] ; then
    echo "~"
else
    echo "$timeLeft"
fi

Geeklet files to download

Comments

User Avatar
7seconds 671 days ago
Cool one, thanks! Anyway, is there any way to show the remaining time in H:M format instead of minutes only?
User Avatar
mosius 671 days ago
Probably some simple "mod" math, but I didn't get into that.
User Avatar
dereks 669 days ago
If you want to break it into an hour a minute display:

isFullyCharged=`ioreg -n AppleSmartBattery | grep FullyCharged | awk '{ print $5 }'`

timeLeft=`ioreg -n AppleSmartBattery | grep TimeRemaining | awk '{ print $5 }'`



if [ $isFullyCharged = "Yes" ] ; then

echo "~"

else



((hour=$timeLeft/60))

((min=$timeLeft-$hour*60))



echo "$hour:$min"

fi
User Avatar
geektool 634 days ago
printf can be convenient in that situation too :

MIN=`ioreg -rn AppleSmartBattery | awk "/TimeRemaining/"'{ print $3 }'`;H=$(( $MIN / 60 ));M=$(( $MIN - ($MIN / 60) * 60 ));printf "%i:%.02i" $H $M
User Avatar
notlob42 558 days ago
so ive been using this one, but I just had to replace my laptop battery. Now for some reason now the geeklet does not send back the same time as clicking on the batter icon. on average it off by an hour. any ideas?

Log in to comment or register here.