6

I am trying to create a script in ARD that will let me logout a user. Now I have a script which does start the logout, but I want it to execute instead of waiting 60 seconds. The script currently is:

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

As I said, this works but then I want it to press return on the logout dialog. The script I tried to make it do that is:

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

which doesn't work.

Is there a way, possibly by telling the system to press Cmd+Opt+q, then Enter, to log out without waiting for the timeout to expire?

Hennes
  • 65,804
  • 7
  • 115
  • 169
Baconlove
  • 63
  • 1
  • 3

3 Answers3

3

The rlgo (kAEReallyLogOut) Apple event logs out without showing a confirmation dialog:

tell application "loginwindow" to «event aevtrlgo»

tell application "System Events" to log out sends loginwindow a logo (kAELogOut) Apple event. The Apple events are listed in AERegistry.h.

Lri
  • 42,502
  • 8
  • 126
  • 159
3

The Apple event is the most robust way to do it (but it can still be blocked by a stuck app).

Entering the special characters is tricky... here's a block you can use in a script or via ARD.

osascript -e 'ignoring application responses' -e 'tell application "loginwindow" to «event aevtrlgo»' -e end

The « and » characters are typed by option-\ and shift-option-\ respectively.

bulge
  • 31
  • 2
1

Keystroke needs to be within a System Events tell block...

osascript -e 'tell application "System Events"' -e 'log out' -e 'keystroke return' -e end
adayzdone
  • 642