For about 2 years I have been looking for a solution to the sleep problems of my Mac Mini, which serves as a mediacenter in the living room. The main problem was that the Mac (Snow Leopard) won’t sleep by itself. When googling for these problems a million of different reasons seem to be responsible for this. However, the number of solutions is limited and I tried them all. I am not alone with this.
The problem with trying to find the actual causes
I’ve spent many hours trying to find the causes why the Mac won’t sleep: ranging from resetting PRAM regularly, varying wakeup options for WOL and Bluetooth, trying to identify individual applications or daemons, which might be responsible for it and so on. It seems that there are just too many different causes that have the same symptom: not sleeping.
That is why I finally gave up looking for the actual cause. Instead I decided to fight the symptoms with additional tooling.
The problem with PleaseSleep
In discussion boards, PleaseSleep is often celebrated as a reasonable solution killing the symptoms. However, the main problem with it is that it cannot be configured easily to not interrupt an EyeTV recording. That is PleaseSleep is pretty much useless for my scenario.
The problem with Narcolepsy 1.0
This is a small script (AppleScript) which is less well known and less often propagated in the web than PleaseSleep. However, it is quite capable of sending the Mac to sleep and even respecting EyeTV recordings and playbacks. The main issue with it is that it simply ignores user interaction (e.g. moving the mouse or typing the keyboard). So, for example when browsing the Web in Firefox, the Mac will just go to sleep – which is annoying.
The solution: Narcolepsy 2.0
I recently put some effort in enhancing the original script from 2008 by Kynan Shook to serve my needs better. I have been using this script for a while now and it works great for me. I believe that it will be useful for a number of people out there as well.
This is the complete information about this version:
This script will attempt to sleep the computer after (approximately) the time specified in Energy Saver. It will not sleep under certain conditions (as originally distributed, if iTunes is playing, EyeTV is playing or recording, DVD Player is open, AirServer is playing Audio or Video content, the local Plex client is playing Audio or Video content or showing pictures). This script is copyright © 2008-2012 Kynan Shook, Torben Schreiter. Permission is granted to modify and redistribute this script, but not for profit.
modification 2012 by Torben Schreiter to extend the original script’s functionality:
– replaced idle check with HIDIdleTime because a wrong number format was returned with the original idle check which resulted in a problem where the Mac goes to sleep despite user interaction –thanks to inspiration by Jason Salaz (http://apple.stackexchange.com/questions/39085/how-can-i-automatically-launch-an-application-whenever-the-mac-goes-idle)
– fixed a problem with sleepDelays smaller than 5 minutes (retryDelay)
– added subroutine to check for CPU load of a process
– added subroutine to retrieve URL
– added default configuration for not sleeping if AirServer is playing Audio or Video content
– added default configuration for not sleeping if the local Plex client is playing Audio or Video content or showing pictures
– added default configuration for not sleeping if the local Plex Media Server is transcoding/streaming (e.g. iPad client)
– Stay awake if any application registered for one of the kernel assertions named PreventSystemSleep or PreventUserIdleSystemSleep or PreventUserIdleDisplaySleep (to monitor type in terminal: “pmset -g assertions”)
– Stay awake if Caffeine is activated
– Stay awake if Finder is copying a file
– added NSUIElement = 1 to Info.plist to not show Narcolepsy in the dock
– Stay awake if the system is printing (note that also open/unprinted print jobs with switched off printer will prevent sleep)
– Stay awake if EyeTV is exporting (e.g. for later iOS playback)
– Stay awake if EyeTV is streaming live TV to iOS App
– added experimental default configuration for not sleeping if EyeTV is streaming to an iOS device (does not work reliably)
– prevent sleep: changed activity detection method from CPU usage to # work queue threads for AirServer
version 2.0.2 (January 30, 2013)
– fix systemSleepDelay detection for Lion and Mountain Lion
– rewrote/refactored timer structure to be easier to understand
– better support for waking up through remote events (e.g. Wake on LAN)
– added debug mode to write debug messages to a log file
– added workaround for iTunes 11 + iOS Remote App bug where iTunes would prevent sleep if an iOS device has a (background) running Remote App without actually playing
version 2.0.3 (March 10, 2013)
– uncommented Caffeine in default configuration because of annoying dialog asking for the location of Caffeine if it is not installed on the current system
version 2.0.4 (November 3, 2013)
– Mavericks compatibility: uncommented Printer Setup Utility in default configuration, because it was deprecated
– Mavericks: Please note that you need to enable the Narcolepsy 2.0 script here: Settings > Security > Privacy > Accessibility
– fix error breaking the sleep check after a fresh reboot
– better error output messages to log for the different applications
version 2.0.5 (April 24, 2014)
– fixed frequently occurring “General error checking Kernel Assertions”
– since OS X 10.9.2: sometimes the own Applescript .app process is creating an assertion blocking going to sleep => we have to ignore all PIDs originating from the script with our name
– removed redundant code
version 2.0.6 (May 29, 2014)
– added some better robustness & debugging output for the getMyName() method
How to install:
– extract .zip
– put a link to the user’s start items for automatic start of the script
– OS X Mavericks: Please note that you need to enable the Narcolepsy 2.0 script here: Settings > Security > Privacy > Accessibility
- Apple iPhone-Headset mit Gigaset DECT-Endgerät verwenden
- Synology Diskstation DS413j w/ IDE/P-ATA drives – working