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?

Log out after X minutes of inactivity

It is an Advanced Option (see the bottom button) in the Security & 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.

  • And your quest to script this would be a very useful journey if you care to learn how AppleScript works to build a list of all the open apps and try to tell them to save or quit as needed. It's just sometimes nice to use the tool already coded if you just want it to work. – bmike Jul 5 '12 at 17:59
  • 1
    Oh come on, that's way too easy... – nohillside Jul 5 '12 at 17:59
  • AppleScript can call arbitrary languages, so I suppose one could do it in Lua or any other counterintuitive language assuming the list of running apps is available and process control is possible to send kill signals. ;-) – bmike Jul 5 '12 at 18:03
  • People should definitively read more kill -9 $(ps aux | grep "^$USER" | cut -b 10-21) for breakfast – nohillside Jul 5 '12 at 18:10
  • Does this log out one user or ALL users, though? – Gorb Mar 13 '13 at 20:35

The other option is if the machine is networked to an OSX server, use Workgropup Manager and define in the group settings. That will allow you set a time out. You can set the time out by the user or workgroup that you have the machine added too.enter image description here

  • This is a tool to manage the same settings as in my answer - so it's a nice trick for a lab full of computers. Now on the more recent OS, you'll make a configuration profile to accomplish the same task as the now deprecated Workgroup Manager and MCX profiles. – bmike Jul 2 '16 at 20:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .