Created
August 22, 2022 06:28
-
-
Save qoopooh/0e06d5ba30d3754e2c768c6edf627d3e to your computer and use it in GitHub Desktop.
Check MacBook battery with command line
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/sh | |
# | |
# Check battery on macbook air 2017 | |
# | |
UNAME=$(uname) | |
if [ "$UNAME" = "Linux" ]; then | |
# find a battery | |
CMD="upower -e" | |
echo $CMD | |
OUT=$($CMD) | |
BAT=$(echo "$OUT" | grep 'BAT') | |
CMD="upower -i $BAT" | |
echo -e "$CMD\n" | |
OUT=$($CMD) | |
PERCENT=$(echo "$OUT" | grep -Eo 'percentage:.+') | |
echo $PERCENT | |
TIME=$(echo "$OUT" | grep -Eo 'time to empty:.+') | |
echo $TIME | |
CYCLE=$(echo "$OUT" | grep -Eo 'charge-cycles:.+') | |
echo $CYCLE | |
else | |
echo "pmset -g batt\n" | |
pmset -g batt | grep -Eo '\d{1,3}%.*' | |
printf "cycle: " | |
system_profiler SPPowerDataType | grep "Cycle Count" | awk '{print $3}' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment