3uq7gw
Last Updated: July 28, 2017
·
9.656K
· mattball
0df2f3c2d3b43605889eb90231fb6884

SSH to many hosts in split panes with iTerm

Opens a new, full screen iTerm window with 2 x n split panes in iTerm 2. Then SSHs to each of the hosts in the hostnames list.

You can drop this file in ~/Library/Application\ Support/iTerm/Scripts and then run the script from the iTerm "Script" menu. Create the Scripts folder if it doesn't exist. If this menu is not visible after this script is in place, just relaunch iTerm.

Requires iTerm2 (this should be obvious), and may not work depending on your key bindings.

set hostnames to {"foo", "bar", "baz", "quux", "corge", "spam", "eggs", "ham"}

launch "iTerm"

tell application "iTerm"
    activate

    -- ssh in split panes to my queue processor hosts
    set myterm to (make new terminal)
    tell myterm
        launch session "Default Session"

        -- make the window fullscreen
        tell i term application "System Events" to key code 36 using command down

        -- split horizontally
        tell i term application "System Events" to keystroke "D" using command down
        -- move to upper split
        tell i term application "System Events" to keystroke "[" using command down

        set num_hosts to count of hostnames

        repeat with n from 1 to num_hosts
            if n - 1 is num_hosts / 2 then
                -- move to lower split
                tell i term application "System Events" to keystroke "]" using command down
            else if n > 1 then
                -- split vertically
                tell i term application "System Events" to keystroke "d" using command down
            end if
            delay 1
            tell the current session to write text "ssh " & (item n of hostnames)
        end repeat
    end tell

end tell    
Say Thanks
Respond

6 Responses
Add your response

13690
E07c504d7ab210248d93cdf93951a5df

so the script menu thing..is that a no go? cause i created the dir in App Support folder for iTerm and nada

over 1 year ago ·
13691
0df2f3c2d3b43605889eb90231fb6884

@hcavillones it certainly works for me. You may need to relaunch iTerm or click "Script → Refresh" in the menu bar.

over 1 year ago ·
13692
E07c504d7ab210248d93cdf93951a5df

ok i got it to show but it won't launch

over 1 year ago ·
13735
E07c504d7ab210248d93cdf93951a5df

also the file has to be saved as a .scpt file in order to activate the Scripts Folder in iTerm2

over 1 year ago ·
22398
None

iTermocil enables you to do this flexibly by defining profiles in YAML files:

https://github.com/TomAnthony/itermocil

(Disclaimer: I wrote it [just for this purpose])

over 1 year ago ·
29143

Hi,

I'm a noob and I'm using iTerm2. I don't see "Scripts" in main menu of iTerm2.
Also, I saved this in file login.scpt and tried to run from Finder window, which took me in AppleScripts. I ran the script, which gave me error "Expected end of line but found identifier" for line of "-- make the window fullscreen"

Please elaborate step-by-step guide on how exactly to create,save and execute this script. Thanks in advance!

5 months ago ·
Filed Under