Published on

Get the Current Battery Level on MacOS with a Shell Command

Authors

Sometimes, we might want to get battery level-related information from CLI. For such cases, pmset command might be a good choice.

Here is how to do it:

# Get battery level - 71%
pmset -g batt | grep -Eo "\d+%"

# Get just number - 71
pmset -g batt | grep -Eo "\d+%" | cut -d% -f1

# Get more details like charging, etc
pmset -g ps / batt

Happy getting battery-level!