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
  • 64,768
  • 7
  • 111
  • 168
Baconlove
  • 63
  • 1
  • 3

3 Answers3

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
2

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
  • 40,894
  • 7
  • 119
  • 157
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
  • 612
  • 4
  • 7
  • This worked. Also, since I am using ARD, it does have a manage menu which has a logout already there. Can use that also, and skip steps. Things you learn. – Baconlove Sep 19 '13 at 16:12