Friday, 22 January 2021

Keep your Mac awake (disable lid and idle sleep) (how to)

A lot of people were using a convenient little application called InsomniaX to disable temporarily the sleep feature on MacOS that is activated due to inactivity after a few minutes or when you close your laptop's lid (screen). 

However, a security vulnerability was identified in the software and after that point in time it is considered a legacy software as it is no longer actively being developed. 

There are alternatives depending on what you want to do. The easiest way to keep the mac from going to sleep is to use a terminal window with the built-in command: caffeinate

However, this does not help when you change focus from that particular terminal window or need to temporarily close your laptop's lid without going into sleep mode. 

In modern versions of MacOS in order to be able to achieve both task (disable lid and idle sleep mode) you will need to run a command. Yes, it is very inconvenient that MacOS does not come with such an option by default, for something to trivial. 

The command to disable both lid and idle sleep mode is:

$ sudo pmset -b sleep 0; sudo pmset -b disablesleep 1

Note: Due to the way security is done in the modern version of MacOS, you will be asked to enter your password in order for the action to be completed.

To re-enable (revert back) as it was, the command is:

$ sudo pmset -b sleep 15; sudo pmset -b disablesleep 0

Tip: When I want to run an overnight task, I do not want to leave the screen powered on all night. In that case the easiest think to do is to use your Mac's F1/F2 keys to lower/turn off - turn on the screen's illumination (backlight). Yes, you could simple close the lid, but the laptop cool a lot more efficiently if the lid is not closed especially if you are going to run an overnight resource hungry/demanding task. 

There are other solutions like Jiggler and Amphetamine (you can find on the AppStore for your Mac). 

I do not like to install additional (third-party) software if I can natively do what I need. Having said that, the Amphetamine app is quite convenient and a decent replacement for InsomniaX. You will have to also install though the Amphetamine Enhancer* (see GitHub page) in order to be able to close the lid without the laptop going into sleep mode. 

FYI: Why is a Separate App Needed? Amphetamine itself is a sandboxed app. All apps distributed through the Mac App Store are sandboxed (it's a requirement). Sandboxing severely limits what an app can do on the Mac. This is usually a good thing from security perspective, as it helps to prevent malware and propagating viruses from taking over or accessing/stealing your personal information. This means that sandboxing restricts certain actions/tasks from executing. The Amphetamine Enhancer is open source (to ensure there is nothing malicious included in the code) and is provided as a separate download. Since Amphetamine Enhancer is not distributed through the App Store, it's not sandboxed and isn't limited in the same ways Amphetamine is.


Where Do I Download the 'Amphetamine' application?
Here on AppStore.

Where Do I Download the 'Amphetamine Enhancer' application?
Here on Github.

Note: Install first Amphetamine from the AppStore, and then download and install the Amphetamine Enhancer. 


* What is Amphetamine Enhancer?

Amphetamine Enhancer is a helper application that enhances a couple of Amphetamine's features. In its 1.0 release, Amphetamine Enhancer adds the following abilities to Amphetamine:

  • Adds a fail-safe for the closed-display mode feature found in Amphetamine 5.0+
  • Gives Amphetamine 5.0+ the ability to use all running processes with Triggers and app-based sessions