We're running tests that require multiple desktops on a Mac Mini.
We're successfully using an ssh TCP tunnel to localhost, 5900 to 6900, to make Screen Sharing let us log into other users on this same machine with vnc://user:password@localhost:6900 and some Applescript to press the resulting dialogue buttons. I can detect successful login via ssh running a program under Java 1.7 with export AWT_TOOLKIT=CToolkit
that tries to open an AWT window as the secondary user, which fails if the desktop isn't started.
This is fairly reliable, although I'd happily hear of more reliable methods!
Where things are going wrong:
We're having problems logging those robot users out, to leave the machine fresh for other tests that object to all the memory wasted by stray processes the users leave running.
I'm currently using
for i in $users ; do
ssh ${i}@localhost "osascript -e 'tell application \"System Events\"'
-e 'log out'
-e 'delay 3'
-e 'keystroke return'
-e end" &
done; wait
but sometimes System Events
apparently isn't running and refuses to start:
33:40: execution error: System Events got an error: Application isn’t running. (-600)
I've recently added -e 'if it is not running then launch' -e 'delay 5'
immediately before the -e 'log out'
but that doesn't seem to do a whole lot to help.
I thought replacing all that Applescript stuff with some variant of ssh kill -KILL -1
would work - at least as a back-up for the hold-out users whose System Events
are broken - but it leaves a good couple of dozens of CoreServices, PrivateFrameworks, and Frameworks GUI-looking things running most of which refuse to die even with kill -9
manually aimed at their PIDs. I tried quite hard with a two-stage script, catching the output of killall -s to a file and squirting it into a second ssh session.
Is there a more reliable way to log these users out and kill all their processes? I have admin rights on the box, but I'd prefer something on the Unix command-line to avoid writing further painful AppleScript to manipulate the GUI.
Thanks!