These steps will vary slightly depending on your version of macOS.
Open
System Preferences.
Click
Battery.
Click Options.
āSet Put hard disks to sleep when possible to Never. If you don't see this option, move on.
āSet Wake for network access to Always.
On the left, click Displays.
āClick Advanced.
āToggle on Prevent automatic sleeping on power adapter when the display is off.
