If you need to prevent your machine from sleeping for a while (like if you've got something running that you really don't want interrupted) there's always caffeinate -t $NUMBER_OF_SECONDS[1]
I haven't experimented with using it to try and keep a machine running with the lid closed, however - that's traditionally considered risky for heat reasons.
I would add caffeinate, which prevents the Mac from going to sleep. It can do this indefinitely, for a fixed period of time, or after a process is done running. You can even specify that process either as the PID of an existing process or by invoking it through caffeinate itself.
You can also just use the built-in Terminal app and run the built-in executable named “caffeinate”, it’s free and provided by Apple: https://ss64.com/osx/caffeinate.html While the command has a few options, just typing the word at the terminal and hitting enter will stop your Mac from going to sleep, etc. A long time ago I worked for a company that had a terrible policy for inactivity screen lock that kept interfering with my ability to get work done, and the caffeinate command helped me prevent screen lock when I needed it to.
Not that I condone this sort of thing, but folks who do need to do it should know about caffeine [0] which allows a Mac to disable it's lid switch and keep running with the lid closed.
Hmm, never heard of that, but I can see myself using this caffeinate command quite often.
Sometimes I leave command line programs running overnight then get annoyed when I find that my Mac went to sleep after an hour because I'd forgotten to adjust the power saving settings.
So running caffeinate -u <my command> will be very handy indeed
KeepingYouAwake is nice (and I'm not about to pretend the following solution is good for everyone), however, I've found on the last couple of McBook fresh installs using caffeinate [1] from the terminal is sufficient.
I usually have a terminal open anyway and `caffeinate -d -t 999999` usually does what I want (stay awake until I come back and tell you to go to sleep). Usually it's two keystrokes away (up arrow, enter), if not, that's quick enough to type for my purposes. That said, it's a bad approach if you want to suggest it as a tool for someone's workflow who _doesn't_ have a terminal open all of the time.
There is a builtin cli tool “caffeinate”. Prefixed to a command it will keep the machine awake until the command exits, on its own it will keep the machine awake indefinitely.
Amphetamine[0] lets you prevent sleep on lid close. I presume it lets you do so without AC power (but I might be wrong on that), but one of the techniques they use to do that (setting the IOKit key that indicates the system is currently in clamshell mode) definitely does work without AC power. I made a command line utility[1] for myself a while back that does that if you're interested. It works fairly well, but the clamshell state tends to reset upon gaining/losing AC power. That's fine if the lid is open at the time (as the utility just applies the change again), but if the lid is closed, the system sleeps until the lid is opened again (at which point, it reapplies the change and you can close the lid again).
The basic command for keeping the machine awake is `caffeinate`, and has a few other nice options like changing what kind of sleep is prevented (disk, display, system) and also waiting on a PID (looks like that was added in 10.10).
Related to that is `pmset -g assertions` which will list all the various things that are keeping your machine from sleeping.
My preference here is to not have the machine sleep at all when it's closed. I do more sysadmin type work than local development type work, and having TCP (SSH) sessions end every time you close the lid would drive me bananas. I would have ruined several laptops in the last few months as our 90 pound great dane puppy has run at me while I was sitting in my chair hacking away.
MacBooks (and MBPs) don't make this easy, which (unfortunately) has kept me on PCs. I've mitigated the ten minutes of BS thing by keeping my machines clean, with an agressive attitude toward junkware, and setting the power button to suspend the computer to disk.
I've made the "i'm using you" / "i'm done using you, good night" command an explicit step this way, but after adapting it's actually kind of nice (even faster than mac sleep/wake) and lets you keep your music and remote terminals alive, which can be convenient at times.
That's funny because I'm pretty sure Windows has a setting that you can set it to NOT go to sleep at all when you shut the lid, but MacBooks DO NOT have this feature.
Do you use one of those apps that keeps your screen open? Caffeine.app and the like? Some of those used to be notorious for keeping the laptop awake when the lid was closed.
1: https://developer.apple.com/library/mac/documentation/Darwin...
I haven't experimented with using it to try and keep a machine running with the lid closed, however - that's traditionally considered risky for heat reasons.
reply