Command Line – Find MacBook Power Status from Command Line

command linemacos

I want to start some rsync jobs in macOS Sierra 10.12 when the power and home network are connected, I know how to use the ipconfig command to check the IP address, but is there anyway to tell whether the power is connected besides grepping the system_profiler? (Which seems a lengthy exercise to get the small snippet)

Best Answer

The pmset command has much shorter output than system_profiler:

pmset -g batt

The first line on my MacBook says "Now drawing from ..." either "AC Power" or "Battery Power" when it runs.