Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Mac Laptop from sleeping when closed?

Tags:

c

macos

I'm writing a program in C and want it to have an option that will keep a mac laptop awake even if the lid is closed so processes can continue. There seems to be very little information available on this topic so I really don't know where to begin. If anyone knows how to accomplish this or where I can find more information I would really appreciate (i.e. will I need to work with the BIOS for this or are there built in functions?). Also, if it's easier to do it in another language that is fine as I'm not stubbornly set on using C.

like image 246
ORL Avatar asked Apr 05 '11 15:04

ORL


People also ask

How do I stop my Mac from sleeping when I close the lid?

To prevent MacBooks from sleeping with the lid closed, click the Apple Logo in the top left corner and click System Preferences. Next, click the Battery option. Once there, tap the Power Adapter option. Tick the box that says Prevent your Mac from automatically sleeping when the display is off.

How do I keep my Mac awake when connected to the monitor?

Set the amount of time your computer or display should wait before going to sleep: Drag the “Turn display off after” slider. Keep your Mac from going to sleep automatically: Select “Prevent your Mac from sleeping automatically when the display is off”.


2 Answers

You need to write a kernel extension for this. The OS doesn't support it by default because the laptops aren't designed to properly cool themselves with the lid closed and internal display enabled. SleepLess is a $10 utility that'll do what you want, too. If you warp the display or something, it's your own fault. :-).

If you want to write something yourself, LidSleep.kext looks like a good start (it does the opposite, i.e. sleeping on lid close) and comes with source code.

(It is possible and supported to wake up some Mac laptops with the screen closed by using an external input device.)

like image 59
Nicholas Riley Avatar answered Oct 15 '22 04:10

Nicholas Riley


You can do this using the I/O Kit framework, see QA1340 listing 2 for sample code using IOPMAssertionCreateWithName to temporarily prevent sleep.

like image 1
Hasturkun Avatar answered Oct 15 '22 03:10

Hasturkun