Setting sleep mode using the command line in OS X. How to prevent your Mac from falling asleep Macbook goes into sleep mode

IN Lately I began to notice that my MacBook Air had difficulty waking up from “sleep”, and several times I even had to turn it off and on again by long pressing the power key. This problem is quite well known to owners of Apple laptops, and in my case it is related to connected devices. But there are a number of other reasons, which I will talk about today. This material will be useful and help solve the problem for anyone who is faced with Mac’s reluctance to come out of hibernation. So, let's go.

How does “sleep mode” work on a MacBook and why do problems arise with it?

Sleep mode on Apple computers is primarily designed to save energy when the device is not in use. The parameters of this mode can be configured in the “System Settings” - “Energy Saving” section. In this post I will not go deep into the setup process; in general, this is unnecessary, everything is intuitive. By and large, there is no difference after how long the system goes to sleep; now we are interested in how to avoid errors when “waking up”.

Please note that there are two sleep mode options: standard and safe. IN safe sleep The Mac goes away when the battery charge is critically low, while the current state of the device is saved in memory: open windows, programs, settings. To exit this mode, you must first connect the laptop to a power outlet and press the power key. Also, do not confuse sleep mode with turning off the display after a certain time (which you set yourself).

Signs that Mac doesn't want to wake up

Depending on your habits and preferences, you can put your Apple computer to sleep in two ways: by clicking on the apple and selecting “Sleep”, or simply by closing the laptop lid. To turn on the MacBook, you must either lift the lid or press any key on the keyboard (you can click the trackpad). After this, an image appears on the screen, and if this is set in the security settings, a field for entering a login password may appear.

If, when you try to “wake up” your Mac, you open the lid or press keys, but there is no reaction, or it is “slow,” these are the symptoms of our case. But before you do anything, consider a number of mandatory conditions. If the MacBook was completely discharged, it will turn on only when connected to charger. At the same time, a trivial remark, but check that the screen brightness is not reduced to a minimum (otherwise you simply will not see the image).

Reasons why macOS sleep mode fails

It is difficult to list them all, since each case is individual, but I will describe the most common:

  1. MacBook battery problems. This category includes both depleted (old) original batteries and replaced new but non-original ones. If the battery has a large number of recharge cycles (about 1000 or more) or low residual charge capacity, then problems may arise with the laptop waking up from sleep. At the same time, counterfeit MacBook batteries do not support all standard functionality; they can randomly turn off the laptop, restart it, and, accordingly, cause sleep problems;
  2. Connected devices and peripherals. An important factor that affects the smooth exit of a Mac from sleep is the connection or disconnection of devices at the wrong time. A simple example: you copied photos from your camera to your MacBook via a cable. Then they simply put it into sleep mode and then turned off the camera, or connected another gadget instead. This may cause a conflict because the system has remembered a different device configuration and will try to restore it;
  3. Non-original SSD drive. It has been observed in practice that non-original SSD drives not only lag behind in writing and reading speed, but also respond more slowly to system startup. Therefore, if you have previously changed the disk and installed a non-original one, then be prepared that “brakes” when exiting sleep mode may become an integral attribute;
  4. FileVault encryption. The standard method of protecting data using disk encryption in macOS often becomes a “double-edged sword.” On the one hand, data is truly almost impossible to seize or hack. On the other hand, if you need encrypted information after force majeure (the disk has failed), then this will not be possible. In addition, FileVault slows down the system, including the process of waking up from sleep.

I did not describe in a separate paragraph the program and system settings associated with background work. For example, a program can spontaneously wake a Mac from sleep and turn it back on during operation. The computer can behave in the same way with certain settings for wireless connections, updates, and notifications. In total, all this may one day lead to a failure in which the system will not be able to “wake up” on its own.

Troubleshooting methods

In fact, ways to solve the problem with a MacBook waking up from sleep arise from the above reasons. If you disconnected and connected peripherals in sleep mode, restart your computer and do not do this in the future. If your laptop’s battery has long been “tired” and barely holds a charge, or it’s not original, it’s worth

When you're not using your Mac, what mode do you usually have it in? Do you leave it in sleep mode or turn it off? Or do you just get up and leave and let “Mac” decide what to do? Surely many Mac users have a question about how to properly “not use” a laptop or desktop computer. Let's figure it out together.


OS X offers us a small choice - either sleep mode or completely shutting down the computer.

Sleeping mode

In sleep mode, both my own and my work Mac spend large quantity time. It is the sleep mode that allows you to return to work in a matter of seconds - all your open web pages, applications, windows are available to you in the form in which you left them, by closing the laptop lid or pressing the button on the back of the iMac.

  • ready to go in seconds
  • You can schedule automatic switches on and back to sleep mode

Against:

  • Energy consumption, albeit low
  • Temporary files, cache and swap are not cleared
  • May cause system slowness (recommended for Macs with at least 4 GB of RAM)
  • For installation automatic updates the computer will have to be restarted manually

If you use your computer every day, then simply leave it in sleep mode, for example, at night. Just remember to reboot it from time to time - this will be useful to maintain system performance and install automatic updates.

Turning off the computer

In general, I almost never turn off the Mac, because after instantly waking up from sleep mode, I no longer want to wait for the Mac to boot from scratch. This is relevant if you know for sure that in the next, say, week you will definitely not turn it on. Using the Windows Restore feature from a previous session can achieve similar results to sleep mode, but the amount of time it takes for the computer to enter work mode is not comparable to waking up from sleep mode.

  • Doesn't waste energy
  • No unnecessary load on the hardware is created
  • All temporary files are cleared upon startup

Against:

  • Long loading time
  • You won't be able to boast of high uptime to geeks

Perhaps the option of completely turning off the computer is suitable for those who are not in a hurry and have a positive attitude towards the idea of ​​saving electricity. Or for those who rarely use a computer. A complete shutdown is also recommended if you plan to not use the computer much for a long time.

Never turn off your Mac

Another option is to not turn off the computer at all. For example, if your computer acts as a server that must work around the clock. On the other hand, if your computer is a server, then you are unlikely to read this post. Therefore, we will not dwell on this option in detail and will move directly to the survey of our readers:

How do you “not use” your Mac: do you leave it in sleep mode or turn it off completely?

August 13, 2013

It happens that you put your Mac into sleep mode, but it only turns off the display. The coolers are working, the network connection is active, the data is rustling back and forth as usual - what is this?! Finding out the reason why the computer does not want to fall asleep is very simple. ;)

The fact is that there is a limited range of software processes, the operation of which directly depends on the activity of your computer. Therefore, they do not allow the system to go into sleep mode in order to continue performing its tasks.

To find out which processes behave so unceremoniously, launch “Terminal”. When you see the prompt ready to accept commands, type pmset -g assertions and press enter. In response, you will receive a whole “sheet” of strange, at first glance, inscriptions.

Scroll the information received to the beginning - there you will see a short list of system variables, of which we are only interested in two: PreventSystemSleep And PreventUserIdleSystemsSleep. If you see a one on the right of at least one of them, it means that there is indeed some kind of program that prevents your Mac from going into sleep mode.

Immediately below the list you will see a list of processes, among which will be our “culprits”. In our example with status DenySystemSleep(i.e. "prevent the system from sleeping") process specified com.apple.InternetSharing. This means that “Internet sharing” is enabled on our computer - it needs to be turned off through “System Preferences”, and then the Mac will be able to sleep unhindered.

In other cases, you can simply "kill" the process that is keeping the system active - either by using console command killall , or through the Activity Monitor. In the second case, you need to find in the list the process that the pmset -g assertions command suggested.

In order to find out the number of minutes after which the computer will go into sleep mode, you need to do:

Sudo systemsetup -getcomputersleep

For example, to configure the computer to go into sleep mode after 1 hour of inactivity:

Sudo systemsetup -setcomputersleep 60

To turn off sleep mode:

Sudo systemsetup -setcomputersleep 0

Sudo systemsetup -setcomputersleep Never

Like any other modern OS, OS X has several sleep modes. Simple sleep - the computer's RAM continues to consume power. Deep sleep (hibernation) - the contents of RAM are copied to HDD.

By default, hibernation mode is enabled only on MacBooks; it can be enabled on other models. Let's look at the current power settings:

Sudo pmset -g

We are interested in the parameter hibernatemode. It can take several values:

    0 - hibernation is disabled;

    3 - hibernation is enabled, the contents of the RAM are copied to the disk, but the power is not turned off;

    25 - hibernation is enabled, the contents of the RAM are copied to the hard drive, then the power is turned off.

Using the parameter standby delay You can set the time in seconds after which the computer will automatically switch from sleep mode to hibernation mode.

To save energy, you can configure your desktop Mac as follows: Turn on Hibernate mode with automatic shutdown food after 15 minutes.

Sudo pmset hibernatemode 3 standbydelay 900

Or we enable a more economical mode, which will turn off the power immediately after copying the RAM

Sudo pmset hibernatemode 25

You can also manually put your Mac to sleep

Pmset sleepnow

While using OS X, some users may notice that the system no longer goes into sleep mode automatically, and all the settings seem to be correct at first glance. In order to understand the situation, let's look at the energy consumption summary and execute in the terminal:

PMset -g assertions

We are interested in the parameter “ PreventUserIdleSystemSleep" if it has the value " 1 ", this means there is some application or service running on the system that is preventing OS X from going to sleep. If you look at the output more closely, in “Listed by owning process” you can see a service that prevents the automatic transition to sleep mode. Output from my computer:

Assertion status system-wide: BackgroundTask 0 ApplePushServiceTask 0 UserIsActive 1 PreventUserIdleDisplaySleep 0 PreventSystemSleep 0 ExternalMedia 1 PreventUserIdleSystemSleep 1 NetworkClientActive 0 Listed by owning process: pid 30(powerd): [..] 121:05:39 ExternalMedia named: "com .apple. powermanagement.externalmediamounted" pid 31(com.apple.serve): [..] 00:14:04 PreventUserIdleSystemSleep named: "com.apple.collabd" pid 75(hidd): [..] 00:01:52 UserIsActive named : "com.apple.iohideventsystem.queue.tickle" Timeout will fire in 21 secs Action=TimeoutActionRelease Kernel Assertions: 0x10c=USB,BT-HID,MAGICWAKE id=503 level=255 0x4=USB mod=09.03.15, 18: 44 description=EHC1 owner=AppleUSBEHCI id=506 level=255 0x100=MAGICWAKE mod=03/09/15, 19:36 description=en0 owner=en0 id=508 level=255 0x8=BT-HID mod=01/01/70, 3: 00 description=com.apple.driver.IOBluetoothHIDDriver owner=BNBMouseDevice id=522 level=255 0x8=BT-HID mod=01.01.70, 3:00 description=com.apple.driver.IOBluetoothHIDDriver owner=AppleBluetoothHIDKeyboard

As you can see, it interferes with " com.apple.collabd", this component is included in the set of utilities OS X Server, and starts even if you do not have any services configured. As far as I understand, this service is necessary for wiki services that can be launched using OS X Server.

In order to disable the service, you must do:

Sudo serverctl disable service=com.apple.collabd

You can then view the summary again if the value " PreventUserIdleSystemSleep", changed to " 0 ", then if there are no other problems, automatic switching to sleep mode should work.

Tested on the following configurations:

OS version
Apple OS X Yosemite (10.10)

MacOS lets you set the amount of time your MacBook's display stays on during periods of inactivity before it turns off, reducing power consumption and increasing battery life. There is a slider that provides from 1 minute to "Never" in the Battery Saver panel in System Preferences. There are 2 sliders: one for when you are running on battery power and another for when you are using the power adapter.

If you want to keep your MacBook awake during long boot times, or just want to keep the display from going dark when you're not watching a video in full screen mode, there's best ways than to delve into System Settings, adjusting one of the above-mentioned sliders, and then remember the need to return the regulator back for normal operation. The first method involves using a free application, and the second using a Terminal command.

1. Third party application.

This is Owly - free application, which you can find in the App Store. It puts an icon in the menu bar that allows you to customize your wake time from 5 minutes to infinity. You can also right-click on the coffee cup icon to launch it with the default duration. Right-click again to disable it.

The owl icon turns red when the app is running, and if you select one of the time steps, the app will place a timer next to the icon. You can disable this timer in the app's settings, as well as set a default duration and configure the app to shut down if the remaining battery charge drops below a certain percentage.

2. Terminal command.

If you don't want to install an additional application to keep your MacBook on, you can turn to Terminal. You'll find Terminal in Applications > Utilities, but you can also just find it using Spotlight.

With Terminal open, enter the following command: caffeine. You will know the command is working if the Terminal title displays "caffeinate". To disable a command, use the keyboard shortcut Control-C. That is, do not type "control", but hold down the key Control, and then press the key C.