-- Launch iTerm and log into multiple servers using SSH
launch application "iTerm"
tell application "iTerm"
activate
-- Read serverlist from file path below
set Servers to paragraphs of (do shell script "/bin/cat $HOME/serverlist")
set num_hosts to count of Servers
set current_host to 1
repeat with nextLine in Servers
-- If line in file is not empty (blank line) do the rest
if length of nextLine is greater than 0 then
set server to "nextLine"
set term to (current terminal)
-- Open a new tab
tell term
if current_host ≥ num_hosts / 2 then
tell i term application "System Events" to keystroke "]" using command down
tell i term application "System Events" to keystroke "D" using {command down, shift down}
else
tell i term application "System Events" to keystroke "d" using command down
end if
delay 1
-- launch session "Default Session"
tell the current session
write text "ssh root@" & nextLine
-- sleep to prevent errors if we spawn too fast
do shell script "/bin/sleep 0.01"
end tell
end tell
end if
set current_host to current_host + 1
end repeat
-- Close the first tab since we do not need it
terminate the first session of the current terminal
end tell