To stop a Mac from sleeping immediately, you can move the mouse or hit a key on the keyboard to show that a user is still present. If you want to make changes within the settings, you can do so from the Energy Saver section of the System Preferences.
Steps
1Click the Apple menu. This is in the upper left corner of the screen.
2Click System Preferences.
3Click Energy Saver.For Mac laptops, the options displayed here will have two separate tabs for Battery and Power Adapter. You will have to set them both if you want the behavior to be the same when using your computer connected to power or on battery.X
4Drag the “Computer sleep” slider. Numbers under the slider indicate how much time must pass without any activity on the computer before it puts itself to sleep.
5Drag the “Turn display off after” slider. Numbers under the slider indicate how much time must pass without any activity on the computer before the screen goes to sleep (the hard disks will remain active).This option may instead appear as “Display Sleep” on some older versions of Mac OS.
6Click the “Prevent computer from sleeping automatically when the display is off” checkbox. This option will stop the computer from entering a full sleep when only the display is asleep.This option will appear in the Power Adapter tab for laptops.
7Uncheck the “Put hard disks to sleep when possible” checkbox. Preventing the hard disks from sleeping means the computer will not enter a full sleep. When in regular display sleep, the computer will react more quickly to a waking action.