5

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)

  • pmset -g batt shows the state of the attached power source. See if that works for you. – Nimesh Neema Jan 28 '19 at 8:21
6

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.

| improve this answer | |
2

pmset -g batt | head -n 1 | cut -d \' -f2

You can just use the delimiter to and escape the single quote to get the extracted text.

| improve this answer | |
1

Maybe help extracted text

pmset -g batt | head -n 1 | cut -c19- | rev | cut -c 2- | rev

output

Battery Power
AC Power
| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .