Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Mountain Lion goes to sleep while still in the middle of a task

This happens with various different apps ie scanning with Image Capture and others that take a bit longer to finish. Also I've had this happening on my both machines, MBP i7 and Mac Pro Westmere 6 core. What is going on?

Oh and Lion did not have this problem, it started (with slow wake up and some wifi oddities) when I upgraded to Mountain Lion.

MacBook Pro, OS X Mountain Lion

Posted on Jul 29, 2012 5:47 PM

Reply
Question marked as Best reply

Posted on Jul 29, 2012 5:52 PM

I use Caffeine (now available from the Mac App Store). A free menubar utility which prevents sleeping. Been using it since SL, because this always was an issue with certain apps.

21 replies

Oct 8, 2012 3:04 AM in response to k1tka

I also have the same problem after upgrading to 10.8.2 from 10.6.8. My iMac go to sleep while it's performing any basic (background) task such as a torrent download, or video recompression (eg. using Handbrake or Apple's Compressor app). Zapping the PRAM and resetting SMC has made no difference nor has the 10.8.2 supplemental update. It seems that the energy saver preferences cannot tell when the mac is on task (When I do not want it to sleep) or idle (when the energy saving feature should kick in and sleep the mac). Please fix this Apple! I don't want to have to resort to 3rd party tweaks to have my mac run properly.

Oct 8, 2012 3:11 AM in response to k1tka

Apparently, it is not a BUG. Apple deliberately changed their energy management policy.

From Mountain Lion onwards, if an application wants to system not to sleep, it needs to declare it explicitly in MacOS. This does not happen for most apps, so the issue here seems to be that programmers and developers need to align to this new policy if they want their app to prevent the Mac from going to sleep while, for instance, streaming, downloading, viewing videos etc.

This is what I have read so far. I am not even sure it is true. Seems crazy to me (it has its logic, but sounds crazy anyway).


The only workaround is to use the Terminal command 'caffeinate'. Works well. It is not clean but does its job...


It is nice to upgrade to Apple's newest OS only to discover these little surprises, similar to what happened with Lion and the SMB protocol changes...

Oct 12, 2012 1:45 AM in response to radio662

I am suffering the same problem since I upgraded from 10.7.4 to 10.8.2. No matter what I do, the iMac will sleep after 5 minutes (this is the timeout I have set) and yesterday I was burning a DVD when that happened: as a result, I had a buffer underrun and I had to throw the DVD away. Thanks Apple.


But has a solution been found? Honestly, I can't yet figure out how to solve this problem. So far, I have decided to set the Mac to "never sleep" in the System Preferences and to put the Mac to sleep only when I need to - it's not what I would like to do but it's the only workaround that maybe will work.

Oct 18, 2012 2:55 AM in response to ciclista71

I have submitted the question to bugreports and Apple has confirmed the following:


"Apps need to use power assertions while engaged on activities that should not be interrupted and we are working to evangelize this.


For you an interim solution would be to use "pmset noidle" in Terminal."

this is not what I want because pmset noidle will just prevent the mac from sleeping but will not resolve the issue. And the evangelization stuff may be quite long before any single programmer decides it's useful to update their software.


So I have studied a workaround which is working quite well, at least for me - you may want to try this out and let me know.


First of all, I have created a bash script that checks CPU usage and lowers a counter each time the mac is in idle state (i.e. Idle CPU reaches at least 93%). When the counter reaches 0 (which means, after 10 minutes of inactivity), the mac goes to sleep with the pmset sleepnow command.


#!/bin/sh


# forcesleep.sh

#

#

# Created by Luca on 16/10/12.

#

minuti=$(cat /Users/luca/.minutes)

valore=$(top -F -R -o cpu -l 3 | grep "CPU usage" | tail -n 1 | awk -F"," {'print $3'} | cut -d"." -f 1)

if [ $valore -gt 93 ]

then

minuti=$((minuti-2))

echo $minuti >/Users/luca/.minutes

else

minuti=10

echo $minuti >/Users/luca/.minutes

fi

if [ $minuti -eq 0 ]

then

echo 10 >>/Users/luca/.minutes

pmset sleepnow

fi


I have then created a LaunchAgent .plist which is called every two minutes:


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

<key>Label</key>

<string>com.luca.forcesleep</string>

<key>ProgramArguments</key>

<array>

<string>/Users/luca/scripts/idlesleep.sh</string>

</array>

<key>Nice</key>

<integer>1</integer>

<key>StartInterval</key>

<integer>120</integer>

<key>RunAtLoad</key>

<true/>

<key>StandardErrorPath</key>

<string>/tmp/sleeperror.txt</string>

<key>StandardOutPath</key>

<string>/tmp/sleepout.txt</string>

</dict>

</plist>


The plist runs every 120 seconds (2 minutes) and executes the bash script I explained before which is located in my home folder, /Users/luca/scripts/idlesleep.sh.

Change "luca" with your home folder name!


You have to save the plist under $HOME/Library/LaunchAgents

My .plist is named com.luca.forcesleep.plist - the name is in the <string>..</string>


Once everything is setup, just run from terminal the following command:


launchctl load $HOME/Library/LaunchAgents/com.luca.forcesleep.plist (or the name you have given to the plist file) and that's it.


You may want to play around with value 93 which is the threshold between idle state and active state and may be different from mac to mac.

Mountain Lion goes to sleep while still in the middle of a task

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.