An AppleScript to automate SSH -X forwarding

From Mac OS X Hints.com http://www.macosxhints.com

An AppleScript to automate SSH -X forwarding
Wed, Apr 21 '04 at 10:13AM • from: toblak

I’m running a Linux server in my home network that I connect to several times during the day. Sometimes I connect just to look at logs, and other times to run X programs, forwarding the display to my G5 using the ssh -x option. After doing this for a while, I got tired of typing in the commands and looked into automating the process with AppleScript. The code below is what I came up with.

To make use of this yourself all you should have to do is set the ServerName, UserName and passwd variables to the correct values. The only other thing you might have to adjust is the delay between sending the SSH command and supplying the password in the ActivateTerminal procedure.

OS version: OS X

global UserName
global ServerName
global passwd

on ActivateX11()
  tell application "X11"
    activate
  end tell
end ActivateX11

on ActivateTerminal()
  set ScriptCommand to "ssh -X " & UserName & "@" & ServerName
  tell application "Terminal"
    activate
    do script ScriptCommand --  Establish the SSH connection
    delay 3 -- Wait 3 seconds for the password prompt to appear
    do script passwd in window 1
  end tell
end ActivateTerminal

on run
  set ServerName to "xxxxxx" --  The name of the server to connect to
  set UserName to "yyyyyy" --  The user to connect as
  set passwd to "zzzzzzz" --  The password for the user
  ActivateX11()
  ActivateTerminal()
end run