Is there a command to find the date and time at which a Macintosh computer last entered the sleep mode?
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. – 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 likepmset -g log | grep -E '^.{24} sleep '
should probably be used in scripts. – Lri 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
-
1This worked for me on 10.11.5:
pmset -g log | grep "Display is turned off" | tail -1
– rgajrawala Jul 1 '16 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). 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%)
-
-
7Use
pmset -g log|grep -e " Sleep " -e " Wake " -e " DarkWake "
for all wakes includingDarkWake
's – Tieme Nov 9 '15 at 17:24 -
-
1
You can also use pmset -g log | grep LidOpen
if you want to know when the lid of your MacBook was opened.
-
1
-
2MacBooks 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. – SomeDude Dec 6 '18 at 8:31 -
1On MacOs High Sierra 10.13 pmset -g log | grep -e "Display is turned on" – max4ever Mar 13 '19 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? – 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
-
@bmike, How to see the time of the last screen password-unlock? (not sleep/unsleep) – Pacerier Mar 30 '18 at 11:12