1

I want to log out a user via a shell script, after a delay. However, there's a few other issues:

  • User does not have admin and/or root.
  • Logout must complete even if screen is locked.

Currently, I'm using the shell commands below to log out:

osascript -e 'tell application "System Events" to log out'
osascript -e 'tell application "System Events" to keystroke return'

This works fine if the screen is active, but if the screen is locked, this fails, because it depends on triggering a window, and then firing an Enter keystroke. As a reminder, techniques like killing loginwindow fail because they require root.

I'm not convinced it's possible; any ideas would be much appreciated.

1
  • When do you want to trigger the log out? After inactivity or on-demand? Commented Mar 18, 2014 at 15:20

1 Answer 1

1

Can you get system events to do Shift-Option-Command-q ?? something like... (I don't know the exact syntax)

'tell application "System Events" to keystroke q with command down option down shift down'
2
  • I don't think that will work, for the same reason the other trick doesn't work: it requires a carriage return, which won't happen when the screen is locked.
    – uint128_t
    Commented Feb 15, 2014 at 3:55
  • This keyboard shortcut doesn't require the user to enter return - it automatically logs you out without any additional interaction. But I don't know if it will work as a script executed while the screen saver is active and locked.
    – John
    Commented Mar 7, 2014 at 20:06

You must log in to answer this question.

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