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.

  • Thank you! I knew the ioreg command, but haven't seen the pmset one. We'll give that a shot!
    – Rosko
    Jan 10 '13 at 17:32

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.)

  • You may also look for NVEthernet::setLinkStatus (in my case magsafeStateChanged wasn't here, and I was trying to get information about how long a power outage lasted) Aug 9 '17 at 21:11

pmset -g rawlog

will show battery details

  • 1
    Welcome to Stack Exchange! Can you please expand on what kind of details that command shows?
    – Kevin Chen
    Jan 17 '13 at 2:39
  • Excellent, this is the answer I was looking for -- here is some sample output: 01/01/15 15:55:34 No AC; Not Charging; 95%; Cap=4545: FCC=4782; Design=5770; Time=3:44; -1217mA; Cycles=450/1000; Location=0; Polled boot=12/31/14 01:49:55; Full=01/01/15 15:55:34; User visible=01/01/15 15:54:34
    – Matt
    Jan 1 '15 at 20:56

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!

You must log in to answer this question.

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