You can make your Mac automatically shut down after a period of inactivity. This ability is not included as standard in Mac OS X; to do this you will need to use Power Manager.
Power Manager includes a built-in task that will make your Mac shut down safely after a period of inactivity. Let's walk through how to create this task.
Create a Shut Down After Inactivity Event
- Launch System Preferences and select Power Manager.
- Click Add… to create a new event.
- Choose the template Power off after inactivity.
- Click Continue to the What and When step.
- By default, the event will Sleep after 15 minutes. Adjust the action to Shut Down and the required period of inactivity to match your needs.
-
Continue through the remaining steps until your event is created.
Having followed the steps above, you will have created a new event in Power Manager. This event will start working immediately and will shut down your Mac after a period of inactivity.

Remember that unsaved changes may be lost if you let your Mac shut down automatically. Always save changes before leaving your Mac unattended.