Sleep a Mac from the Command Line
Sleep can be invoked instantly on any Mac through the command line by running the pmset command or a very simple AppleScript. To try this yourself, launch Terminal and use one of the following commands, remember there is no warning, sleep is immediate:
That is one of the most simple uses of pmset, which is a full featured power management utility.
You can also use AppleScript to instantly initiate sleep from Terminal:
osascript -e 'tell application "Finder" to sleep'
osascript is a command line tool that runs OSA scripts, the -e flag executes the script in quotes rather than looking for a file, and the text in quotations is basic AppleScript.
Using either method should override anything else running in Mac OS X and force the system to sleep. You can also target the application “System Events” if you do encounter something preventing sleep:
osascript -e 'tell application "System Events" to sleep'
The latter AppleScript is also used in our guide on how to remotely put a Mac to sleep using an iPhone or ssh.