Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

TL;DR: Internet Sharing is preventing my Mac from sleeping. I need to manually sleep the system on a regular basis. I want a way to configure Internet Sharing to stop preventing sleep.

I have an iMac at home in my bedroom too far away from my router, and I can't use wireless, also, 3G coverage here is awful, so I've enabled Internet Sharing so I can use my iPhone/iPad connected trough my iMac.

At work I am on a corporate network and wireless is somewhat lame and too restrictive, so I've enabled Internet Sharing on my MacBook Pro there too, so my iPhone can reach internal stuff.

The problem is: When I hit ++ (or  > Sleep) neither computer goes to sleep as desired; that is unless I disable Internet Sharing first.

At home I want the computer to sleep while I sleep (saves power + more silence) and at work when going home I want it to sleep too, so I don't have to close all connected apps (Adium, Colloquy, etc) and reopen again the next day.

How can I configure pmset or Internet Sharing so I can sleep my computer without running into this problem?

Note: I've already used pmset to check if there were other reasons and the offending pid is always com.apple.InternetSharing.

Edit: I realize that sleeping the computer will make it impossible to use Internet Sharing. I want it to sleep completely and I want Internet Sharing to be on again only when the computer awakes.

share|improve this question
    
My output to the command above is DenySystemSleep. Although I found the string, I was unable to use sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.nat to change the behavior. Could you expand you answer a bit? –  Irae May 1 '12 at 6:31
    
So, for example, you want something that will turn off sharing, then sleep. And something else that will, automatically on wake, turn on sharing. –  GEdgar May 25 '12 at 14:07
    
Exactly! This is what i need –  Irae May 30 '12 at 20:33

4 Answers 4

up vote 4 down vote accepted

I have experimented with using ControlPlane to achieve what you want. My preliminary result is that it will do what you want.

ControlPlane detects changes to your system called 'evidence sources'. Changes are evaluated with 'rules' which define a change in 'context'. Associated with each context are 'actions'.

One of the 'evidence sources' is a sleep/wake event. So I have configured a rule so that on a sleep event (e.g. you have clicked sleep in the Apple menu), the context 'Sleepy Time' is triggered. And for this context I have used the action 'ToggleInternetSharing' to off.

After clicking on Sleep, I get an alert saying that Internet Sharing is being turned off and after a little while (seems like forever but is probably only 10 or 20 seconds) the Mac goes to sleep.

And I have a second rule so that on a wake event the context 'Waking Up' is triggered and this has the action to set 'ToggleInternetSharing' on.

My Rules and Actions:

enter image description here enter image description here

Try it!

This is just scratching the surface of what ControlPlane can do.

share|improve this answer
    
Amazing app! It worked like a charm! Many thanks for the detailed explanation. Also, I did check that the app is completely free and open source. For me this counts as a plus in favor of using it =) –  Irae Mar 19 '13 at 1:45
    
I have known about ControlPlane for some time, but not used it. Your question was an excellent reason to explore its capabilities - thanks for that. –  Gilby Mar 19 '13 at 5:33
    
+1 here... With OS X Mavericks v10.9.4 and still works like a charm. Thank's –  gmo Jul 11 at 6:56

If you are running Lion, InternetSharing is explicitely locking the SystemSleep. Have a look at:

strings /usr/libexec/InternetSharing | grep SystemSleep

The output of this command: DenySystemSleep is the proof that InternetSharing is purposefully blocking the kernel possibility to go to sleep. There is a simple explanation to this protection: once InternetSharing is fired, clients of this Mac may be using it as a router to access the Internet. A lot of thing may be automatically running on top of this Internet connexion without any knowledge of the person in front of the screen.

This connexion should only be broken by the admin of the system who started it and not any automatic system behaviour.

This is a safe behaviour.

Hence the correct method to ensure InternetSharing is off when the Mac sleep is to schedule 4 events in the following order:

InternetSharing off
    system sleep
    system wakeup
InternetSharing on

This is the scheduling offered by ControlPlane.

share|improve this answer
    
My output to the command above is DenySystemSleep. Although I found the string, I was unable to use sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.nat to change the behavior. Could you expand you answer a bit? –  Irae May 1 '12 at 6:31
1  
I believe @daniel-azuelos means to demonstration that InternetSharing is responsible. The command he suggests searches through the InternetSharing binary and finds the string related to blocking sleep. This helps confirm what is likely to be responsible for blocking sleep, but not for getting your desired behaviour. –  Graham Miln Mar 3 '13 at 12:15
    
→ Graham : thank you ;). –  daniel Azuelos Mar 7 '13 at 15:04

When your computer's power management unit makes the device sleep, it enters a low-power mode. Your average executable code on the computer is not run in the normal manner: the computer maintains enough power to refresh the memory (if necessary) and little else. You're not going to be able to engage in general-purpose computing while the computer sleeps.

However, there is a good alternative that you should look at. Instead of sleeping the entire unit, check out display sleep in System Preferences -> Energy Saver. In my use-case, I have a hot-corner setup (which you can enable in System Preferences -> Desktop & Screen Saver -> Screen Saver) so that when I'm going to lunch and need to lock my screen and/or just put the display to sleep, I move to the bottom-left corner. Works well for me, the computer doesn't come back up from a sleep-routine and any long-running processes I've forgotten about aren't interrupted. In your case, this means that your WiFi hotspot won't get dropped.

share|improve this answer
1  
This is indeed very useful, I use <kbd>^</kbd>+<kbd>⇧</kbd>+<kbd>⏏</kbd> to do that. But it's not what I wish. I don't need Internet Sharing while the computer sleeps. I need the computer to really sleep and even turning sharing and the wifi off. Will edit my question to clarify. Thanks anyway =) –  Irae Apr 12 '12 at 14:57

You can use Power Manager to put your Mac to sleep after periods of inactivity. Power Manager can overrule processes and applications that block idle sleep, including Internet Sharing.

The user guide walks through how to set this up:

A Better Inactivity Triggered Sleep

Power Manager offers an alternative. We provide an inactivity triggered sleep. Inactivity is measured differently from idle time; inactivity is a simpler measurement determined solely by user activity.

Alternatively, the following recipe shows how to create a Power Manager event to put your Mac to sleep after a period of inactivity.

Power Manager: Power off after inactivity task

Disclaimer: I work for the company who develop Power Manager.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.