Logout user script

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?

Baconlove

Posted 2013-09-19T13:24:00.770

Reputation: 63

Answers

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

Posted 2013-09-19T13:24:00.770

Reputation: 592

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 – 2013-09-19T16:12:26.383

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

Posted 2013-09-19T13:24:00.770

Reputation: 31

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

Posted 2013-09-19T13:24:00.770

Reputation: 34 501