Shutdown or Sleep a Mac via Command Line (Via SSH too)

Recently, I was working from remote and was accessing my Mac via Command line for some research purpose. And I thought it would make sense to share what I know about controlling the Mac from a remote location via Command Line or another Terminal.

I was accessing my Mac via Prompt for iPhone and iPad, and these commands also work on any other command line tool. Now, let’s go one by one.

Sleep a Mac via Terminal:

Just fireup any command line tool, and connect it to your remote Mac. I will put up a tutorial on how to do that the right way. And just type the following command:

osascript -e 'tell application "System Events" to sleep'

This would put all the System Events to sleep, which means, the entire Mac would start sleeping right after receiving this command. Now, let’s take a look at this next thing. Which is to Shutdown a Mac via Command Line.

Shutdown a Mac via Terminal:

Just fireup any command line tool, and connect it to your remote Mac. I will put up a tutorial on how to do that the right way. And just type the following command:

sudo shutdown -r now

Again, just like any other command, there will not be any confirmation about Shutting down the Mac.

Hope this helps. Next up would be to automate the Shutdown or Sleep process via Email or a IM to your Mac, which is connected to the internet.

Subscribe to 4CAST

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 23 other subscribers