8

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.

  • 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 Carvalho 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 Carvalho May 30 '12 at 20:33
7
+50

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.

  • 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 Carvalho 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 '14 at 6:56
  • Seems like a great application! Unfortunately, toggling Internet Sharing does not work in El Capitan for the time being (probably not in Sierra either). – Winterflags Oct 29 '16 at 15:41
2

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.

  • 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 Carvalho 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
1

It is not practical to have a Mac with Internet Sharing enabled be able to go to sleep.

The Internet Sharing feature is the software version of a router: It acts as a gateway to the internet, a DHCP server, a firewall, and a DNS forwarder. It's functions just like the routers you can buy from your local retailer; and it's free.

However, there’s a massive downside: If the Mac that acts as the gateway is turned off or asleep, then the other machines can’t get online.

This is why Internet Sharing prevents your machine from going to sleep.

But I can share files/iTunes/Screen When It's Asleep

Yes, you can share all those things, and more. However, when you go to access those files your Mac wakes up. This is called Wake On Demand and Bonjour Sleep Proxy.

When your Mac is asleep, it keeps the network connection somewhat "live;" it's listening on for the Bonjour "packets" to wake up the computer. This is handled by the Airport device (the network adapter) itself; not the computer. When it receives the "wake packet" the Mac wakes up and you can start of your sharing of resources.

Bonjour1 is a zero config discovery service that uses multicast Domain Name Services (mDNS) which is a UDP2 protocol (it's broadcast and can't be routed) which is a small, stateless and minimal message-oriented transport.

Basically, UDP (what Bonjour is based on) is perfect to send a message to your computer to say "Wake up!"

In order to browse the Internt (use a computer behind the gateway Mac), you need the full protocol stack which is based on TCP. It will need DHCP, NAT, firewall, etc. which means it will have to spin up all those services prior to allowing clients to browse the web. This will introduce a great deal of latency.

And going back to a more pragmatic approach, if your Mac did go to sleep and acted as a gateway, it would either never go to sleep or would be up and down like someone with a bad case of insomnia.


1Bonjour is Apple's implementation of zero-configuration networking (zeroconf), a group of technologies that includes service discovery, address assignment, and hostname resolution. Bonjour locates devices such as printers, other computers, and the services that those devices offer on a local network using multicast Domain Name System (mDNS) service records.

2UDP is a minimal message-oriented transport layer protocol. UDP provides no guarantees to the upper layer protocol for message delivery and the UDP layer retains no state of UDP messages once sent. It is simple, suitable for bootstrapping or other purposes without a full protocol stack, such as the DHCP and Trivial File Transfer Protocol.

  • Allan, thanks for your insight. In my particular case, I only make use of Internet Sharing because of a MBP that I connect to my iMac via Thunderbolt Bridge to gain the advantage of Ethernet (100 Mbit instead of ~30 Mbit Wifi). I don't use Internet Sharing as a ‘router’. It would therefore be practical for me to find a way via script or automatisation to enable/disable Internet Sharing (or force sleep). – Winterflags Oct 30 '16 at 8:45
  • Internet Sharing is turning your Mac into a router - that's the core function of what Internet sharing does. – Allan Nov 4 '16 at 15:24
  • I understand, but I'm not speaking about it in technical terms. I make use of Internet Sharing only when connecting the MBP via Thunderbolt Bridge to the iMac, and it therefore doesn't make sense to have the iMac never go to sleep regardless if it's connected or not. Therefore looking for a workaround, perhaps involving scripting. – Winterflags Nov 4 '16 at 15:30
  • 1
    Well, you're not going to overrule Internet Sharing from preventing your MBP from going to sleep, but if you want a "workaround" look here: apple.stackexchange.com/questions/2488/… – Allan Nov 4 '16 at 15:34
  • Thanks - I've tried those answers already and haven't been able to get them to work with El Capitan (perhaps due to SIP), but will have to investigate further. – Winterflags Nov 4 '16 at 16:08
0

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.

  • 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 Carvalho Apr 12 '12 at 14:57
0

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.

  • Didn't work for me with Internet Sharing active. -1 for wasting an hour of my life. – Winterflags Oct 29 '16 at 15:20
  • What did you want to achieve and what did not work for you? – Graham Miln Oct 29 '16 at 15:35
  • Same as the OP and your answer. I configured Inactivity Sleep, in hopes that it would 'Force Sleep' with Internet Sharing enabled in System Preferences > Sharing. It didn't, but it would activate sleep if Internet Sharing was disabled. – Winterflags Oct 29 '16 at 15:37
  • 1
    Power Manager issues a sleep request to macOS. If you are having problems with sleep, as the other question indicates, then the same sleep problems will also affect sleep requests issued by third party applications. Of course, I may be mistaken or simple wrong in my understanding of your situation. I hope you can find a solution. – Graham Miln Oct 29 '16 at 16:32
  • 1
    macOS will always sleep when explicitly asked to sleep – Finder > Apple (menu) > Sleep. Not sleeping is behaviour that suggests problems with the Mac. – Graham Miln Oct 29 '16 at 16:42

You must log in to answer this question.

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