Terminal command to determine the last time a MacBook Pro was unplugged from AC Power?
We have multiple users that are assigned MacBook Pro's who we know never take them away from their desks. We need some sort of proof to repurpose this hardware and issue them an iMac. We would really like a terminal command we can send or a script we could run to determine the last time the laptop was unplugged.
So far everything we've found just tells you its current state, but not "timer"?
You might be able to use ioreg to determine the cycle count of the battery. A low cycle count indicates that the battery has not been discharged and charged very much.
ioreg -l | grep Capacity
"Cycle Count" shows how many times the battery has been cycled. You can read more about battery cycle counts here.
Another idea is to use pmset to log the state of the system's power. You could, in theory, have that dump to a file to investigate after some time has passed.
Take a look at the man page for pmset.
pmset -g pslog
will log the state of system's power. As the device is unplugged or plugged you'll see the log update. This could show how frequently a notebook is unplugged and charged. If it remains plugged in for long spans of time, or is often drawing from 'AC Power' then you'd know if it's mobile or not.
I had a similar dilemma and I actually greped the syslog for the magsafeStateChanged event... worked like a charm. In the terminal:
syslog | grep magsafeStateChanged
It should return:
Jun 17 03:39:19 computername loginwindow[43] <Notice>: magsafeStateChanged state changed old 2 new 1
Your milage my vary, but for me state 2 is unplugged and state 1 is plugged in. (I determined this by tailing syslog while unplugging the device.)
pmset -g rawlog
will show battery details
I'll third the suggestion of pmset's logs, however an easier way to access that log (tested under 10.8) is to open System Information, go down to the Software section, pick the Logs subsection and you should see "Power Management logs". Hope this helps!