Francesco's posts

Prevent your Macbook from Sleeping when Lid is Closed

Since I discovered working from  command line, I found enlightenment in life… Ok, jokes. But being able to run incredibly useful scripts with just a few words typed -and with no other app messing with the system or running in the background- has been a game changer. All you need is a keyboard and a terminal window! One of the most useful command I discovered is “caffeinate”, whose processes probably underlie apps like “IsomniaX”.
macbookoldclosed

Macbooks by default are set up so that they will sleep whenever you close the lid, unless they are plugged into an external monitor, keyboard, and mouse. But, what if you want to close your laptop and run to your friend on the other side of the floor to show him your new running app? What if you are listening to some music? What if you want to download or backup at night? Ever wanted to shut the laptop but didn’t want to stop its processes?

 

Caffeinate Your Mac!

To begin running the caffeinate command and prevent your Mac from sleeping, open the Terminal located in /Applications/Utilities, then type the following command:

caffeinate

While this command is running, you will be able to close the lid on your Mac and still have OS X and your apps running and performing their tasks just as you would if the lid were to remain open.

screenshot-2016-12-05-08-15-51

Caffeinate Your Mac for a specified length of time

You can also caffeinate your MacBook for a  specific length of time.

caffeinate -u -t 2100

With the command above, replace “1800” with the number of seconds that you wish the caffeinated command to run. Running this command as-is will cause your Mac to prevent sleeping for 30 minutes (1800 seconds).

Once starting this command, your Mac will be prevented from sleeping for the set amount of time, and will automatically terminate the caffeinate program afterwards, which will cause your Mac to go to sleep soon thereafter.

Cancel the Caffeine

To make the caffeinate command stop running and return your Mac to normal using either of the methods above, simply return to the command line and press the sequence

Control + C

screenshot-2016-12-05-08-16-18

Further Options

If you want to explore different options available through caffeinate, just type

man caffeine

This will display a list of additional functions you can access by adding the relevant extensions to you caffeinate command.

To quit the displayed manual just type “q

Attention

If you close the terminal window that is keeping your Mac awake, the commands being executed will stop! Also, you should avoid keeping your Mac running with the lid closed for long periods whilst inside of a bag or otherwise covered up. Doing so will cause heat to build up and could cause damage to your laptop.

 

Francesco Perticarari

 

 

References:
techradar.com (March 2014)

Leave a Reply

Your e-mail address will not be published. Required fields are marked *