NMS Sleep Utility

A Simple Approach to Laptop Insomnia

NMS Sleep Assist and NMSd
TripWire NM-FS made friendly!


Home Site Map Recent Activities PM 8500 Project SlicedApple (NMS) Guest Book


The NMS Sleep Utility is intended to help with failures of automatic system sleep on OS X systems. Skip the Recent News and Go Straight to the Main Site Content for a description of NMS, or to get an idea if NMS will help your system sleep see Will NMS Work for Me?


Recent NMS News  

March
4th, 2006

NMS v2.3 beta 3 is available. This is a very small update that resolves some display glitches in NMS Sleep Assist and NMS Monitor.


February 28th, 2006

NMS v2.3 beta 2 is available. (The beta 2 link now leads to beta 3).


February 14th, 2006

NMS Utility and the new Intel-based Macs.

I had a chance to do some limited testing of NMS v2.3 beta 1 on a 2 GHz Intel Core Duo iMac. The NMS Utility including NMS Sleep Assist, NMSd, NMS Monitor what Script Additions I tested all functioned as expected. Therefore I expect the NMS Utility to work fine on those systems.

 February 5th, 2006

NMS v2.3 beta 1 is available.

This revision has actually been finished since October 11th, 2005 but I have been too busy to post it. This first beta (beta 1) does not reflect all the changes I intend for v2.3 and so far is just a completion of the Sleep Assist GUI and configuration controls to bring it to par with the capabilities of NMSd.

NMS v2.3 beta 1's only real change is ehancement of the Non-ESI Settings window to allow full configuration of NMS's Autonomous mode including separate time-to-sleep settings for different power sources. This is useful for users who want to use NMS completely independent of Energy Saver's time-to-sleep settings.

NMS Monitor has not been updated and therefore works as in v2.2 R (Final).

There is little reason
to download this first beta of v2.3 for those happily using v2.2 R either in Panther, or using default ESI mode in Tiger.

Older NMS News  


October 9th, 2005


NMS v2.2 is Final.

Although there are a few more things I would have liked to have added to v2.2 it has been stable for quite awhile now
and already has so many major changes from v2.1 it really should be v3.0.  I didn't want to change anything else before releasing a known stable version for users to download and v2.1 needed to be replaced as a Final. At some point you just have to draw the line and call a version finished before you screw it up.

N
ew or evolving features are being added to v2.3 which should be posted as an early beta (alpha?) within a few days (the main change right now is the ability to configure the Autonomous mode use of source specific idle times plus some other NMS Sleep Assist Improvements). I also plan to slow the rate of NMS's development way down from here on out.

NMS v2.3 will involve a number of changes but I intend to add them one at a time and post a beta after each.



What's New for Version 2.2 of the NMS Utility 

NMS v2.2 is a significant expansion of NMS's features and configurability over NMS v2.1.

NMS now correctly handles a larger variety of situations including those where sleeping should actally be held and it can be configured for a much wider variety of situations where the user defines exactly what correct is. This includes managing unattended wake events such as those resulting from modems or the computer waking on a schedule, plus the ability to be configured on a per-application basis. Specific enhancements and bug fixes to the NMS background application should also to improve it's ability to sleep unusually reluctant systems.  The entire codebase underwent a major cleanup and re-organization as part of a review of NMS's overall paradigm.

Several large bugs present in v2.1's NMSd were identifed that were not evident on my systems the most important the infamous MATHABS bug. This bug essentially kept NMSd from using it's semi-clever tiered sleeping system I devised for systems that resisted sleeping on the initial attempt. For most users either NMSd slept on the first shot or it was out of bullets.  Fortunately the first shot was effective almost everytime but a subset of users could be identified for whom NMSd did not seem to work, but where I knew that it should work. Hopefully that is now resolved.

The Sleep Holds system was expanded in a number of ways, mainly for power users. It can now see processes outside its own user space, hold for a process anytime it is running, and be configured directly from the NMS Sleep Assist GUI.

A specific hold was implimented to account for scheduled or automated wake events. Unattended wake-ups do not reset the idle timers so as far as NMS v2.1 was concerned the system should have by all rights still been sleeping, and that is exaclty where NMS v2.1 and earlier would put the system. This made a scheduled wake-up for something like an automated back-up problematic. NMS v2.2 now recognizes idle-wake events and holds sleep in response to them for the full duration off it's normal time-to-sleep interval.

Support for individual Time-to-Sleep settings for different power sources for the fully Autonomous mode was added and, although missing from the GUI, is easily setup using the Script Additions.

NMS Sleep Assist was improved (or worsened), often to match new NMSd abilities. NMS Sleep Assist now sports better dialogs, banishing of the Disclaimer to only once and, most importantly, an arbitrary and random total reworking of the GUI concept to HYPER-Tech. Several new features have also been added such as an "Always Hard Sleep" option, a new mode for extended sleep failures, and the addition of new or  improved Activities Sleep Holds, including While Printing, While Burning, and While on Dial-Up plus the ability to use more complex manual Sleep Holds and that can now be setup from the GUI. There was also a significant amount of work towards Panther friendly changes, a bettery installation protocol for new users, and improvement to the GUI handling of Install/Uninstall and Start/Stop.

The Script Additions were completely overhauled and expanded and a number of new Script Menu items were added including many for setting prefs along with others for testing. Of most significance is the reworking of the NMSd Status monitor application. It was renamed several times eventually coming to rest on NMS Monitor and re-rewritten to make it dynamic, smaller and less space wasting (it even has a"mini" mode), and to act much more like an NMSd control applet. The Timer interface has been improved and incorporated into NMS Monitor and along with a new option of hard sleeping on Timer end, plus with a bit of aTimer reminder function.

For Comparison: NMS versions before 2.0 saw the system in only one state, Awake.  Sleeping was not even tracked, it was just ordered and then ignored. NMS v2.0 saw three states, Awake, Sleeping, and Insomina and had two responses to sleep being called, Slept and Other. NMS v2.1 saw four states,
Awake, Sleeping, Sleep Held and Insomina plus the two responses. NMS v2.2 sees seven states, Awake, Sleeping, Sleep Held, Idle-wake hold, Sleep Held during Idle-wake Hold, Insomina and Refractory Insomina, and four responses to sleep being called, Slept, Canceled, Held, and Failed with Error. This increase in the granularity of states and responses allows NMS to do the "expected" thing more often and allows more complex configurations and tuning.


The list of changes.
NMS v2.2 beta 1 thru Final are included in the following change list.

NMSd (background daemon)

NMS Sleep Assist  (installatin/configuration utility)


Script Menu Additions

This list is unusually condensed because there were a very large number of changes.
  1. Main window further reduced in size plus a second smaller "mini" mode added. The "mini" mode always floats and shows a subset of what the Full mode displays
  2. Much more control and information with better feedback about what the user did, can do, and the sate of any embedded controls
  3. Monitoring code rewritten to greatly reduce overhead and resource use
  4. All full sized displays now have embedded controls
  5. Additional controls added and Timer controls moved from external script, expanded, and improved
  6. When active NMS Monitor will provide an alert (defeatable) when the Timer is nearly up
  7. Help expanded and improved with better and more detailed explanations
  8. Absorbed the other main Additions
  9. Options for starting and/or quitting the NMSd application and opening NMS Sleep Assist
  10. Master mode for using NMSd selectively or causing NMSd to seem like a visible application with NMS Monitor as it's GUI


Feedback and Observations on NMS 
Since NMS includes several ideas that we are all trying out I am going to collect and post observations and findings so they are collected in one place.

A couple of my own observations.

Sleep Holds

iTunes, Mail, and Aquisition work well.

The Printing Hold from v2.2 works pefect in Tiger and improved but not perfect in Panther.

Disk Burning and Dial Up activities holds work well.

Safari works unreliably. As expected animations kick up its CPU use.

A good sleep hold for Software Update is to set the manual hold:   Software Update.root:-0.5  (This will be added as a Quick-Pick for v2.3)

The most interesting so far was mplayer. It seems that mplayer tickles the actual idletimers while playing movies.  While it was running (playing a movie) the idle timers did not advance at all (I thought NMSd had crashed for awhile). This affected built-in functions like dimming the display as well as NMS. I have not looked at mplayer to see if this is an intentional built-in feature, preference, or something else.

Disk Burning (at least using OEM software on OEM drives) can also tickle the idle timers.

Bluetooth

Confirmed - Bluetooth MS mice mess with sleep and it can be avoided by disabling 'allow Bluetooth devices to wake the system'

Confirmed - A Bluetooth headset can hold the system in a semi-sleep until the batteries run dry (semi-sleep means no application is running so NMS is out of the game), cause bounces with sleep failures, or just sluggish sleep onset, and can do so apparantly at random.



* Issues of Note Regarding
Bluetooth


A number of Bluetooth input devices can cause sleep problems, especially 3rd party Bluetooth mice.  NMS can force sleep but it can't keep a rouge mouse or headset from waking the system back up.

Input devices are specifically permitted to wake an OS X system and Bluetooth devices can do so as well. The trouble is that even when nothing is happening and the computer is starting to count sheep certain Bluetooth devices JUST WON'T SHUT UP. Often what you get is a pattern of successful sleep with immediate waking (bouncing), or sleep that can't be revived (the sleep of death).
If you are having problems with your system freezing on sleep or bouncing and you are using any Bluetooth devices, especially a Bluetooth mouse (the MS Mouse is the most notable) try turning off the option in your Bluetooth Preferences "Allow Bluetooth devices to wake this computer" and see if that helps. If it doesn't work try disabling all Bluetooth devices including the system's internal module or external USB dongle that serves as its Bluetooth hardware .

Bluetooth headsets can be especially difficult exhibited random or hard to predict behavior. I have observed that a Bluetooth headset within reach of an OS X system can cause problems ranging from sluggish onset of sleep to bouncing with every sleep attempt causing total sleep failure to semi-sleep with battery drain until a forced sleep results. These events DO NOT seem related to whether the device is actually selected in the Sound Preference pane, or whether the system was the most recent device the headset was paired with, but only to the headset being unpaired (not already connected to something else, like a phone) and therefore searching for a mate. The problems are inconsistent which makes them hard to isolate. If you are having random sleep problems and have a headset try TURNING IT OFF for several days or removing it from the area and see if that helps the problem.

This is a complex issue but I think derives from the same core problem. Many if not most headsets do not understand OS X sleep never get the memo and therefore never stop trying to reconnect. Depending on your luck that might result in a sleep crash, continuous bounces, or something else. This is not surprising since a headsets design emphasis is on maintaining a connection to a cell phone where sleeping is simply not a concern.


 



What is the NMS Utility?

 
NMS is My Answer to My Laptop SIMPLY REFUSING!!! to Sleep Automatically
 
See Will NMS Work For Me? to get my best guess at whether NMS will help your sleep problems.

I live on my laptop and a huge pet peeve of mine is laptop Insomnia.  It has plagued every Apple laptop I have used, even before OS X (although sleeping then was so unstable it was best to avoid it). Slowly (or not slow slowly) my system would loose the ability to sleep automatically, although sleep could usually be restored with lots work consisting of some combination of permissions repairs, combo-udpate re-installs, Open Firmware and/or power manager resets, or even dissassembly to remove the PRAM battery. It was a pain, sleep always eventually failed again, and invariably progressed to the point where it could not be fixed without a wipe and reinstall.


Not using my laptop Heavy and Hard is not an option, but having it run out of juice frequently because I have to leave quickly, get caught on the phone, have a sudden bout of explosive projective vomiting (or its southern counterpart), or any other reason I might forget to manually sleep my laptop... well, that's just not cutting it either. 
Whats worse is I have had systems that are so not-sleepy that they run the battery totally dead and then turn off the slow-die way which quickly kills a $100 battery.

I just need to count on my system sleeping!!!


What I want for a solution is simple.  I want my OS X laptop to sleep absolutely reliably while on battery power so I never have to think about it, or fix it.  I don't want the solution to be complicated (those fail too), and I want it to be cheap (or free).


I want Bulletproof and Cheap!

NMS is my answer.  

I ran the original
Panther version of NMS for some time and my laptop ALWAYS went to sleep within 6 minutes and IT WAS GREAT!!

That version was very simple with no options. It forced sleep within three minutes of the Screen Saver. Since I kept the Screen Saver on 3 minutes my system slept somewhere randomly from three to six minutes after idle. 
 
Then Tiger came along and broke NMS, but since I was busy so didn't work on it for some time.  Eventually I got sick of the insomnia plus received a flurry of emails asking about it, so I changed the one line of code required. NMS then worked in Tiger. (Released as v1.11)

I had a dead weekend as it turned out (everyone gone, car in shop) so I decided to try and make NMS a little more useful and flexible so that others might get more benefit. I added the obvious improvements although it is was still pretty basic. 


I then really got to playing and updated NMS quite a bit more than that so that it could
poll the HID hardware idle timers itself to operate completely independent of the Screen Saver, or continue to use the Screen Saver if that worked better. It was still stable, still with low overhead, and slept reliably plus it now sported an installation/configuration application with a much improved and less kludgly set of controls and options (hell, it had options).

Of course NMS continued to grow from there to support direct binding to Battery or AC power independent of the Energy Saver settings (including power source specific time-to-sleep settings as of NMSv2.2b5) and an Energy Saver Integration mode  where NMS used Energy Saver's settings as its own.

AND STILL
I found out how much I didn't now about system sleep which led to more improvements. NMS is now quite a bit more sophisticated than I ever intended. In order to provide ever close to the "expected" or desired behavior NMS has a number of automated and manual adaptations to WHEN and IF to force sleep based on various settings and it's take of what's actually happening on the host system. It also has tracking of and flexible responses to sleep failures, the ability to have most of it's instrinsic control parameters adjusted using preferences, a reasonably granular ability to be configured on a per application basis, plus a few extras like a monitoring and control applet, a Timer, and more. If even has SOIL.
 
How NMS Works

NMS solves (for me) the constant problem of an invariably corrupt power manager preventing automatic sleep, especially on laptops, and so far NMS has been bullet proof for me. Obviously it will not work for everyone.

NMS is just a run and stay-open AppleScript application that has been made faceless (doesn't show up anywhwere in the GUI when it's running) that every so often checks in and when it sees the system has been idling for long enough, or the screensaver is running, it puts the system to sleep using a much less ignorable version of the sleep command than Energy Saver uses.  Where Energy Saver says 'Come on honey, aren't you tired, what do you think about going night, night' with the system responding 'In a minute honey', NMSd is more the drill instructer approach of 'LIGHTs OUT IN 15 SECONDS, IN YOUR BUNKS NOW...NOW NOW NOW NOW!!!'

Its Sleep Dammit, and it works.

NMS is really a simple application that uses built-in sleep just like Energy Saver, just a different aspect of it. The included Instructions have much more detail.



The Real NMS is hidden in NMS Sleep Assist. It is the NMSd application.

NMSd is the application that runs invisibly in the background, watches for the need for sleep, checks the Sleep Holds, sets up Panther compatibility, but never takes a bow.


                                             ...the Shadow knows...


     NMSd background application
 
Will NMS Work for Me?

Probably the most honest answer is "I am just some guy with an Apple laptop who got frustrated enough to solve this problem for himself, so how the heck should I know?" but I will give what SHOULD be the technically correct answer and almost certainly usually is.

The Bottom Line

If you are running OS X 10.3 or 10.4 and if you can put your system to sleep manually using the Apple menu (meaning your system can sleep) and then wake the system back up normally then NMS should work for you. In fact if it doesn't work for you in that case I want to know because it REALLY SHOULD. (I have NOT yet had a chance to test NMS on an Intel based Mac).

If you have a laptop that will sleep by closing the lid but not by manually selecting the menu item then NMS might work, that is an odd case.

Huh?


Well, first, NMS was originally written using OS X 10.3 and continues to be developed in OS X 10.4 and so it works on those systems. It is possible it works or can be modifed to work in OS X 10.2 but I have not tested it. OS X 10.0 and 10.1 barely supported any real power management at all so I find it hard to imagine NMS working there.

Beyond system version considerations whether NMS works for you depends on what type of problem you have, software or hardware. You can more or less divide sleeping problems into one of these two types: 1) The system doesn't go to sleep because the power management program that is part of OS X never called for sleep (it's corrupt or it was blocked), or 2) hardware problems are interfering with sleep.

NMS deals with number one
, software causes. This is typically the result of some process intentially or unintentially waiving off or preventing sleep when the system wishes to call for it. 

Hardware problems show up as machines that will not go to sleep even manually, machines that crash or freeze on sleep so you can't wake them back up, or machines that bounce on sleep (wake right back up).
Theoretically I may be able to address certain specific hardware cases by killing key drivers or changing key settings just before sleep but I have not looked into that much at this point.

Looking beyond theory to practically and noting hardware problems stem from conflicts involving hardware drivers, the OS X kernel and various firmwares it is not fair to say that dealing with such issues is beyond my abilities. Clearly dealing with such issues is laughably beyond my abilities.


If your machines freezes when it goes to sleep it will do so for NMS as well. If you machine bounces it will bounce for NMS. NMS may then successfully sleep your machine on its second attempt 30 seconds later, but then so would have Energy Saver.

A common scenario is this: A user has a system with both types of problems, software so that sleep is never ordered, and hardware, darned lucky because if sleep ever was ordered the machine would freeze anyway. That user then installs NMS and gets (to his irritation) a freezing machine each time it should sleep. NMS gets blamed and deleted which is Ok since for any benefit both problems would need to be solved making NMS a non-solution for that user
anyway.

How Do I Fix the Hardware Problems?
 
Ditch the hardware.

Oooh...look of pain...Ok, maybe not always, just usually. After doing the obvious step of getting the newest drivers and firmware for ALL your hardware then
usually you have to choose, keep the hardware, or be able to sleep.

Some types of hardware problems can be worked with. See the information about Bluetooth issues on this page. You can also download NMS and look at the later parts of its manual for some additional information.


Download NMS

The current non-beta version is NMS v2.2 R
. The newest version is NMS v2.3 beta 3.  
(If you are a new user I would recommend NMS v2.3 beta.)
 

Click on the A-OK to Download NMS v2.2

 
 





More Details About Security, Reliablity, Sysem Overhead

Plus the License and Disclaimer


Safety and Security

?  Will it throb my system, spew files everywhere, install secrets, see me naked  ?
 
 
Short answer, No, so far NMS has been rock stable and it doesn't modify your system.
 
 
NMS might see you naked, we don't discuss those sorts of things. Otherwise NMS is as safe and un-intrusive as I can make it. Except for the user copying NMS to their drive and NMS creating preference files in your user Preferences folder NMS only copies a single file, the actual background application, to your Library folder. The only preferences (besides its own) that NMS modifies is the Screen Saver idle time (and only if you  chose to change it from NMS), and the login preference by the act of adding a new login item. Installing the Script Additions places those in your Library folder as well.

Outside of those settings NMS doesn't alter the system settings in any way including those related to sleep or Energy Saver. NMS runs and lives completely in user space and will never ask for your password (except for one exception)* or touch any files outside of your home folder.

I am not aware of any cases of NMSd (the background daemon) crashing (where it stops running from sudden quits, freezes, etc), causing crashes, causing system slowdowns, even during my development efforts.

*Since NMSd will now optionally force Sleep even when the installing user is "Switched Out" via Fast User Switching I require an Admin password to activate that ability IF Energy Saver Integration is NOT being used. This  is to prevent anyone from activating a potentially hard to find faceless process (if you don't already know about it) that can effect other users on computer they don't own or aren't responsible for.

Resource Use and Overhead


?  Will this slow my system down  ?
 

Short answer, No, NMS seems to have trivial and impercetible impact on system resources.


When I looked at this in Panther running NMSv1.0 I used subjective feel while using my system for video playback, etc plus ran some general benchmarks with NMSd running and not running. This limited testing found the NMS background application had no measurable or appreciable impact on system performance either subjectively or with benchmarks.

That was my impression with the newer version as well but out of curiosity and because of the addition of some more complexity including checking of the HID idle timers directly I did a little more investigation for v2.0. These test are not rigid but also not optimized for performance. They are a quick and dirty look to make sure nothing bad is happening.

I tested NMSd build 1302 from NMSv2.0 running on a PowerBook G4 12 in 1.33 and OS X 10.4.2. The system had been running for a number of days and had all my normal background processes runnning, plus some visible processes to.

I found trivial overhead and that most of the overhead that did exist was actually from having the system call the the NMSd idle handler in the first place and the interprocess messaging that resulted but what code the handler ran (in the specific case of NMSd) added little. Almost no extra extra time was required to run the HID timer poll, or even write to the log, although normally I have NMSd log very little, almost never unless it is actually about to sleep.

Since logging did not have any real impact on overhead and being interested in users for whom NMSd doesn't sleep along with the need to help fix any problems for others I now have NMSd log more liberally.


Testing using with my laptop on battery with CPU cycling set to Automatic, and with NMSd set to sleep on battery and use direct HID timer polling I got these results:

With NMSd having a sleep time of 4 minutes NMSd consumes between 0.04 to 0.05 % of the processing power.

With the worst case scenario of NMSd having set to sleep time of 10 seconds (the hard coded limit in NMSd)  NMSd consumes 1.1 to 1.2 % of the processing power.

Addendum for NMS v2.1 and v2.2

NMS v2.1 is a bit different since it has to capture the Energy Saver settings on each idle check while in ESI mode and it turns out the pmset utility is SLOW. The result from the addition of that one call made an order of magnitude difference in CPU use by NMS. Fortunately overhead was solow before that even with the increase it is still insignificant.

v2.1 running using its own settings and not set to use the new ESI mode has resource use similar to v2.0.

When using v2.1 in ESI mode I found resource use of around 0.3% on Battery and 0.2% on AC. This is using my laptop which was NOT optimized and had been running for a number of days and started in its normal configuration The system is a 1.33GHz G4 with processor cycling set to automatic for Battery and Highest for AC.

NMS v2.1 includes a new function to estimate resource use by running a simple test. The results are certainly approximations but they can give you an idea. A script to use this function can be found in the new Script Menu Additions.

NMS v2.2/2.3 uses about 30 to 50% less CPU power than v2.1 because of some optimizations to the idle check handler, but remaining below the threshhold for humans to percieve it makes no real difference.

Chicken Shit and Ass-Covering Section


License, Warnings, Disclaimer


This software is released released AS IS WITHOUT ANY SUPPORT OR WARRANTY.  If is messes up your computer, has an affair with your wife, or destroys your life then you were warned.

The NMS Utility and its components are released as "What_the_Hell_Ware". They are free (as in beer...warm generic beer...but free) and may be distributed and modified without limit provided the Quick Start Guide and this disclaimer, license, and warning accompany them.

If you use NMS and had fun, or thought it was a little cool, send me an email.  If you thought it was stupid, well, you don't have to send an email...really.




 
 
 
Visit Counters

This Page

Sliced Apple (All)

 

Document made with Nvu

 

 

Created        7/16/05
Modified     7/22/05          -    Updated to reflect v2.0 Read Me, features, download.
Modified     7/24-8/5/05   -    NMS v2.1 beta 3 - beta 5.
Modified     8/6/05             -    NMS v2.1 b6
Modified     8/12/05          -    NMS v2.1 b8
Modified     8/14/05          -    NMS v2.1 FC1
Modified     8/15/05          -    NMS v2.1 FC2
Modified     8/18/05          -    NMS v2.1 FC3 (Final)
Modified     8/21/05          -    New NMS icons. Tidbit about NMS v2.2.
Modified     8/31/05          -    NMS v2.2 beta 1
Modified     9/1/05            -    NMS v2.2 beta 1b
Modified     9/~10/05        -    NMS v2.2 beta 3
Modified     9/19-20/05    -    NMS v2.2 beta 4
Modified     9/29/05          -    NMS v2.2 beta 5
Modified    10/2/05           -    NMS v2.2 FC1
Modified    10/4/05           -    NMS v2.2 R
Modified    10/9/05           -    NMS v2.2 R Final and mention of v2.3 beta
Modified    2/5/06             -    NMS v2.3 beta 1 posted
Modified    2/7/06             -    Misc content corrections
Modified    2/14/06           -    Updated to reflect initial Mactel testing
Modified    2/28/06           -    NMS v2.3 beta 2 posted
Modified    3/4/06             -    NMS v2.3 beta 3 posted