Setting energy saver settings from the command line
You can use the pmset tool to set various energy saver settings. Do a man pmset in the Terminal to get a full listing of options for this utility. The following will turn off screen dimming, hard drive spin down, and machine sleeping while the machine is on the charger. You can replace -c with -b to edit the settings for the battery.
sudo pmset -c dim 0 spindown 0 sleep 0
If you want to turn these features on, just replace the zeroes with a number indicating the number of minutes. So to send the machine to sleep after 15 minutes of inactivity when it’s on the battery, use:
sudo pmset -b sleep 15
This command must be run as root, or by using sudo.