Any way to put OS X to sleep via Terminal?

Joined
Mar 19, 2007
Messages
1,814
Reaction score
137
Points
63
Location
NY USA
Your Mac's Specs
iMac 5.1 | iMac 7.1 | iMac 12.1 | iMac 19.1 | iPhone 11 Pro | Watch s5
You need a shell script:

#!/bin/bash
osascript << EOT
tell application "System Events"
sleep
end
EOT

It's not a one-liner.
 

kjb


Joined
Apr 3, 2013
Messages
2
Reaction score
0
Points
1
Use 'pmset' -- Do a 'man pmset' for full options...

So, to put your system to sleep via CLI, in terminal:

-$ pmset sleepnow

This is more straight forward than mucking about with osascript (though I do enjoy discovering more and more and more osascript trickery!).
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
You're about 8 years late to the conversation. ;)
 

kjb


Joined
Apr 3, 2013
Messages
2
Reaction score
0
Points
1
Yea, I hope that is OK -- I don't usually have the opportunity to help, and I realized I could answer this one for "somebody, sometime, hopefully"... :Cool:

All best to all...
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Oh, that's not a problem at all. I just wanted to point that out in case you were hoping that the original poster would find your answer.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top