Use osascript and system events via SSH to control GUI
Dec 14, '04 09:16:00AM • Contributed by: sophistry
Dec 14, '04 09:16:00AM • Contributed by: sophistry
Sometimes Timbuktu crashes and I restart it using SSH:
$ sudo kill -9 PID_for_timbuktu_host
$ open -a Timbuktu\ Pro.app
That usually works because the app starts the host again. But maybe you need to fix something, and you don't have access to a Timbuktu-enabled machine; just SSH. You can use osascript to call System Events to trigger menu actions, keystrokes, and dialog box navigation all via SSH. Just use the open -a shell command to get the application you want to have open to open and become frontmost, then send it osascript with System Events commands. It's kind of like driving while blindfolded, so be careful! It helps to have a local system with a similar setup, so you can test the osascript command before you run it "blind." Or better yet, work out your osa GUI control scripts while you watch via Apple Remote Desktop (ARD), VNC or Timbuktu. Here's a trivial example:
$ open -a Stickies.app ; osascript -e 'tell application "system events"' \
-e 'keystroke "n" using command down' -e 'keystroke "Wow!"' -e 'end tell'
I use this technique to deal with some password dialog box issues in using a FilemakerPro setup. Sometimes the FMPro database won't start up without a password and it blocks everything else with its pesky dialog box. I can use this little script technique to just spit the password into the dialog box as if I were sitting there (or at an ARD, VNC or Timbuktu screen).
•
[14,300 views]
