MacOS – How to trigger lid close action programmatically

hardwarelidmacossleep-wake

Is there a way to trigger the lid close action programmatically with a script or through terminal?

I am testing this by placing a small magnet near the SD slot on my MacBook Pro.

Best Answer

There is no Apple supported programming interface to simulate the lid being closed.

You can put your Mac to sleep using this command line:

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