• Mac OS X,  Mass Deployment

    Scripting a Battery Sanity Check

    When I’m running a script that might be somewhat time intensive I like to check the battery of the MacBooks first. Otherwise I might end up hosing some machines that die out in the middle of a script. To do so I’ll use ioreg to grab the maximum load that a battery can sustain, stored in MaxCapacity: capacity=`ioreg -l | grep MaxCapacity | cut -c 35-39` Then I’ll grab the current load on the battery, stored in CurrentCapacity: current=`ioreg -l | grep CurrentCapacity | cut -c 39-43` Finally I’ll grab a percentage: echo “scale=2; $current*100/$capacity” | bc If the percentage is above a certain threshold then I’ll run the script,…