0

Sometimes I close my laptop, assuming that there is nothing running that prevents sleep, put it in my bag, and then find the next day that it didn't sleep - instead it ran out of battery and shut down.

Is there any way to see which apps or processes were preventing it from sleeping? It doesn't do this always so I don't want a manual method I have to do before I close the lid.

Note I am not asking which processes are currently draining the battery.

  • Is this you are asking? macworld.com/article/1168151/software-utilities/… – Pratik Jun 6 '18 at 9:25
  • No, because that shows current information. I want to know what already has drained my battery (and is no longer running). It does look very useful though - if there's a way to trigger logging it when I close the laptop lid then that might work. – Timmmm Jun 6 '18 at 10:34
  • Why not just run the command and save output through a bash script. While the computer is asleep, it will just be paused, and if it is awake, it will continue to save the process names so you can identify the issue yourself. – Rushil Srivastava Jun 6 '18 at 23:36
1

I commented this but realized it is really just a solution. Building off on what @Pratik commented, using the command found here, build a simple bash script to save the output every 2 minutes. You can run this script right before you put the computer to sleep to determine what is keeping your computer awake. If the computer goes to sleep, then this program will be paused, but if it is awake, it will continue to record the process keeping your computer awake. You can change the counter yourself if you find it to to be too much or too less.

Sample Bash Program:

mkdir -p sleep_logs
cd sleep_logs
clear

echo "Starting monitoring programs."

while true
do
    ###Save command output
    pmset -g assertions > $(date +%H.%M.%S_%Y.%m.%d).txt
    echo "Command Saved @ $(date +%H.%M.%S_%Y.%m.%d)"
    wait

    ###Change time here
    sleep 2m
done

echo "Terminated"
  • I'll try this. I expect there is a a way to trigger it from a lid-close event somehow to make it a bit more intelligent but it'll do. – Timmmm Jun 7 '18 at 19:34

You must log in to answer this question.

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