How to trigger lid close action programmatically? 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.
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'