2015-04-23

OS X: Determine power source is connected or not in command line

Use ioreg :

ioreg -rc "AppleSmartBattery" |grep ExternalConnected|awk '{print $3}' | grep -q '^Yes$'

(see exit code)

Today accidentally our MacBook for Jenkins Slave has down -- due to power source loss. So I've added cron job to notify my team that power cable is disconnected based on this one liner.

Referral

Published at 2015-04-23 00:09:33 +0900 | Permalink