Skip to content

Instantly share code, notes, and snippets.

@baybatu
Forked from Bonno/README.md
Created March 5, 2020 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baybatu/a2accce2537203b4eb0adf6b1f975b99 to your computer and use it in GitHub Desktop.
Save baybatu/a2accce2537203b4eb0adf6b1f975b99 to your computer and use it in GitHub Desktop.
Opening multiple SSH sessions with iTerm automatically. To be used in an Automator flow.

Create a new Automater flow

Add 'Service'. Service receives 'no input' in 'iTerm'. Add 'Run AppleScript'.

-- Launch iTerm and log into multiple servers using SSH
tell application "iTerm"
activate
create window with default profile
-- Read serverlist from file path below
set Servers to paragraphs of (do shell script "/bin/cat $HOME/serverlist")
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)
-- set term to (make new terminal)
-- Open a new tab
-- tell term
tell current window
create tab with default profile
tell current session
write text "ssh " & nextLine
-- sleep to prevent errors if we spawn too fast
do shell script "/bin/sleep 0.01"
end tell
end tell
end if
end repeat
-- Close the first tab since we do not need it
-- terminate the first session of the current terminal
tell first tab of current window
close
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment