Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Is there a command to find the date and time at which a Macintosh computer last entered the sleep mode?

share|improve this question

3 Answers 3

up vote 12 down vote accepted

You can use the pmset command to obtain this information. The following command obtains a log of the sleep/wake entries then restricts this to the last entry in the list which should be the most recent sleep:

pmset -g log | grep sleep | tail -n 1

You can obviously play around with anything after pmset -g log to give you what you need.

share|improve this answer
    
hey thanks that worked! just changed the grep command to grep -2 sleep to get the line with the date and time. –  newenglander May 24 '12 at 18:24
    
Oh yes, now that's what I'm talking about. Precise sleep info and not some log file grepping hoping to catch a hint of sleep. :-) –  bmike May 24 '12 at 21:40
    
grep sleep might also match other lines. Something like pmset -g log | grep -E '^.{24} sleep ' should probably be used in scripts. –  ؘؘؘؘ May 25 '12 at 9:29
    
@Lri Agreed. I did lash the original command up in about 5 seconds and is also why I added the last sentence ;-) Thanks for the correction. –  binarybob May 25 '12 at 9:38

Actually, something like

pmset -g log|grep -e " Sleep  " -e " Wake  "

is what really gives me a clean timeline of sleep/wake events on 10.8.2. powerd does not log anything about it, at least on my system (10.8.2, MacBook Pro Retina 15). The formatting on this site does not do justice to the clean output seen on a shell (that is, given enough width to the window):

02/03/13 19:48:37 GMT-03 Sleep Maintenance Sleep Sleep: Using AC (Charge:99%) 26 secs
02/03/13 19:49:03 GMT-03 Sleep Maintenance Sleep Sleep: Using AC (Charge:99%) 27 secs
02/03/13 19:49:30 GMT-03 Sleep Maintenance Sleep Sleep: Using AC (Charge:99%) 26 secs
02/03/13 19:49:56 GMT-03 Sleep Maintenance Sleep Sleep: Using AC (Charge:99%) 26 secs
02/03/13 19:50:22 GMT-03 Sleep Maintenance Sleep Sleep: Using AC (Charge:99%) 26 secs
02/03/13 19:50:48 GMT-03 Sleep Maintenance Sleep Sleep: Using AC (Charge:99%) 26 secs
02/03/13 19:51:14 GMT-03 Sleep Maintenance Sleep Sleep: Using AC (Charge:100%) 1802 secs 02/03/13 20:39:17 GMT-03 Sleep Maintenance Sleep Sleep: Using BATT (Charge:100%) 244 secs
02/03/13 20:43:21 GMT-03 Sleep Maintenance Sleep Sleep: Using AC (Charge:100%) 51 secs
02/03/13 21:07:17 GMT-03 Sleep Maintenance Sleep Sleep: Using BATT (Charge:100%) 242 secs
02/03/13 21:11:19 GMT-03 Sleep Maintenance Sleep Sleep: Using AC (Charge:100%) 1103 secs 02/03/13 21:29:42 GMT-03 Wake Wake due to EC.LidOpen/Lid Open: Using AC (Charge:100%)
03/03/13 00:00:26 GMT-03 Sleep Idle Sleep Sleep: Using BATT (Charge:85%) 96 secs
03/03/13 00:02:02 GMT-03 Sleep Maintenance Sleep Sleep: Using AC (Charge:85%) 38 secs
03/03/13 00:02:40 GMT-03 Wake Wake due to EHC1/HID Activity: Using AC (Charge:85%) 4338 secs 03/03/13 01:14:58 GMT-03 Sleep Clamshell Sleep to DarkWake: Using AC (Charge:100%) 48382 secs 03/03/13 14:41:20 GMT-03 Wake DarkWake to FullWake due to HID Activity: Using AC (Charge:100%) 728 secs
03/03/13 14:53:28 GMT-03 Sleep Clamshell Sleep to DarkWake: Using AC (Charge:100%) 415 secs
03/03/13 15:00:23 GMT-03 Wake DarkWake to FullWake due to HID Activity: Using AC (Charge:100%) 718 secs
03/03/13 15:12:21 GMT-03 Sleep Clamshell Sleep to DarkWake: Using AC (Charge:100%) 156 secs
03/03/13 15:14:57 GMT-03 Wake DarkWake to FullWake due to HID Activity: Using AC (Charge:100%) 834 secs
03/03/13 15:28:51 GMT-03 Sleep Clamshell Sleep to DarkWake: Using AC (Charge:100%) 378 secs
03/03/13 15:35:09 GMT-03 Wake DarkWake to FullWake due to HID Activity: Using AC (Charge:100%)

share|improve this answer

There may be a more efficient way to get the exact last time, but on lion you can search for powerd entries in /private/var/log/system.log

If you like terminal, something like grep powerd /private/var/log/system.log works well. The Console app also has a nice search ability to filter these logs.

If there was no sleep event since the last time the the log file rolled over, you can use Console or bzgrep instead of grep to search the system.log.*.bz2 files.

share|improve this answer
    
I don't get any results for powerd in any of the system logs, could I be missing some setting for logging powerd activities? –  newenglander May 24 '12 at 17:41
    
If you sleep and wake and that doesn't show, then you might just look at the file at the exact time you slept the mac to see the messages your mac is making. –  bmike May 24 '12 at 21:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.