Skip to content

Instantly share code, notes, and snippets.

@Bonno
Last active August 11, 2023 14:13
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save Bonno/d131ec80701dcbb640f68d89823199b5 to your computer and use it in GitHub Desktop.
Save Bonno/d131ec80701dcbb640f68d89823199b5 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