Last active
April 29, 2018 06:25
-
-
Save davidraedev/7fc06d3344e3c3981c05c59282355d1d to your computer and use it in GitHub Desktop.
Macbook / OSX / MacOS Battery Health Logger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LOG="$HOME/log/battery.log"; | |
# create TSV headers if log file does not exist | |
if [ ! -f "$LOG" ]; then | |
echo "Creating Log File"; | |
echo -e "Date\tCurrent Charge\tMax Charge\tCycle Count\tCondition\tAmperage\tVoltage" > "$LOG"; | |
fi; | |
DATE="$( date +%s )"; | |
REMAINING="$( system_profiler SPPowerDataType | grep 'Charge Remaining' | awk '{ print $4 }' )"; | |
CAPACITY="$( system_profiler SPPowerDataType | grep 'Full Charge Capacity' | awk '{ print $5 }' )"; | |
CYCLES="$( system_profiler SPPowerDataType | grep 'Cycle Count' | awk '{ print $3 }' )"; | |
CONDITION="$( system_profiler SPPowerDataType | grep 'Condition' | awk '{ print $2 }' )"; | |
AMPS="$( system_profiler SPPowerDataType | grep 'Amperage' | awk '{ print $3 }' )"; | |
VOLTS="$( system_profiler SPPowerDataType | grep 'Voltage' | awk '{ print $3 }' )"; | |
echo -e "$DATE\t$REMAINING\t$CAPACITY\t$CYCLES\t$CONDITION\t$AMPS\t$VOLTS" >> "$LOG"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment