Is there a command to find the date and time at which a Macintosh computer last entered the sleep mode?
4 Answers
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.
-
2hey thanks that worked! just changed the
grep
command togrep -2 sleep
to get the line with the date and time. Commented May 24, 2012 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 ♦Commented May 24, 2012 at 21:40
-
grep sleep
might also match other lines. Something likepmset -g log | grep -E '^.{24} sleep '
should probably be used in scripts.– LriCommented May 25, 2012 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. Commented May 25, 2012 at 9:38
-
5This worked for me on 10.11.5:
pmset -g log | grep "Display is turned off" | tail -1
Commented Jul 1, 2016 at 20:42
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).
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%)
You can also use pmset -g log | grep LidOpen
if you want to know when the lid of your MacBook was opened.
-
3
-
4MacBooks enter sleep mode 15 seconds after the lid is closed. You can see when your machine entered sleep mode due to closing the lid with the command
pmset -g log | grep 'Clamshell Sleep'
. Subtract 15 seconds to get the exact time the lid was closed.– SomeDudeCommented Dec 6, 2018 at 8:31 -
3On MacOs High Sierra 10.13 pmset -g log | grep -e "Display is turned on"– max4everCommented Mar 13, 2019 at 10:43
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
.
-
I don't get any results for
powerd
in any of the system logs, could I be missing some setting for loggingpowerd
activities? Commented May 24, 2012 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 ♦Commented May 24, 2012 at 21:39
-
@bmike, How to see the time of the last screen password-unlock? (not sleep/unsleep)– PacerierCommented Mar 30, 2018 at 11:12