Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

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.

share|improve this answer
    
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... –  patrix 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 –  patrix Jul 5 '12 at 18:10
    
Does this log out one user or ALL users, though? –  Damian Mar 13 '13 at 20:35
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.