Applescript to kill open applications and log out user after 30 min. of inactivity I'm looking for a way to automatically log off a user after 30 minutes of inactivity, as well as close all open applications. As of now, there is really only one user to deal with. I'd prefer an easy (free) way of doing this, but am open to using a program that might accomplish the same thing. Thus far, I've come up with the following Applescript to close all programs and log out:  

tell application "System Events"
    key down {command, shift, option}
    keystroke "Q"
    key up {command, shift, option}
end tell


I'm not sure how to go about finding the period of inactivity. I don't have much programming experience, so any detailed step-by-step would be appreciated.
Have you tried using the built in tools to force a log out upon reaching a certain idle time?



It is an Advanced Option (see the bottom button) in the Security &amp; Privacy preference pane on Lion.

If you want one user to have a different timeout you can script things easily with Automator or AppleScript:

tell application "System Events"
    log out
end tell


The trick is making your custom app keep a timer for 30 minutes of inactivity which is why the system control panel is the best option for this request.