Saturday, July 23, 2011

Applescript to connect using SSH

Assume one has a Mac. Uses iTerm2. And that one spends a great deal of time managing a riot of Unix systems using SSH.

Now use this AppleScript to launch a new terminal window, then login to your remote host. Now - as the joke goes - you have four problems.

The interesting part were variables, which I did not know how to pass to Applescript. So I learned something: hey, hey hey.


$ hostname


on run argv
tell application "iTerm"

-- This causes script to operate on current terminal (window)
-- set term to (current terminal)

-- make a new terminal
set term to (make new terminal)

-- Open a new tab
tell term
set Lsession to (make new session at the end of sessions)
tell Lsession
set name to (item 1 of argv)
exec command "ssh username@" & item 1 of argv & " "
end tell
end tell

end tell

end run
#! /bin/bash
source $HOME/.conf/remote.conf
echo "-----------------------------"
echo "Take off, hoser"
echo "-----------------------------"
cd $HOME/bin
osascript $HOME/bin/s2.scpt $1
blog comments powered by Disqus