Skip to content

Instantly share code, notes, and snippets.

@brablc
Forked from bmfurtado/cssh.applescript
Created January 17, 2014 21:51

Revisions

  1. @bmfurtado bmfurtado revised this gist Apr 20, 2013. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion cssh.applescript
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,8 @@ on run argv
    return
    end if

    set rightArrow to ASCII character 29

    set numServers to count serverList

    set numHorizontal to (round (numServers ^ 0.5) rounding up)
    @@ -38,7 +40,7 @@ on run argv
    repeat createdPanels times
    -- re-evaluate number of vertical panels we need
    set numVertical to (round((numServers-createdPanels)/(numHorizontal-splitColumns)) rounding up) + 1
    tell i term application "System Events" to keystroke "]" using {command down}
    tell i term application "System Events" to keystroke rightArrow using {option down, command down}
    repeat numVertical - 1 times
    if createdPanels is less than numServers
    tell i term application "System Events" to keystroke "d" using {command down, shift down}
  2. @bmfurtado bmfurtado revised this gist Apr 16, 2013. 1 changed file with 7 additions and 4 deletions.
    11 changes: 7 additions & 4 deletions cssh.applescript
    Original file line number Diff line number Diff line change
    @@ -15,9 +15,7 @@ on run argv

    set numServers to count serverList

    -- number of panels we should end up with
    set numHorizontal to (round (numServers ^ 0.5) rounding up)
    set numVertical to (round (numServers / numHorizontal) rounding up)

    set createdPanels to 1

    @@ -34,19 +32,24 @@ on run argv
    set createdPanels to createdPanels + 1
    end repeat

    set splitColumns to 0

    -- split each of the panels vertically
    repeat createdPanels times
    -- re-evaluate number of vertical panels we need
    set numVertical to (round((numServers-createdPanels)/(numHorizontal-splitColumns)) rounding up) + 1
    tell i term application "System Events" to keystroke "]" using {command down}
    repeat numVertical - 1 times
    if createdPanels is less than (count serverList)
    if createdPanels is less than numServers
    tell i term application "System Events" to keystroke "d" using {command down, shift down}
    set createdPanels to createdPanels + 1
    end if
    end repeat
    set splitColumns to splitColumns+1
    end repeat

    -- open ssh sessions--
    repeat with loopIndex from 1 to (count serverList)
    repeat with loopIndex from 1 to numServers
    set currentServer to item loopIndex of serverList
    tell item loopIndex of sessions to write text "ssh " & currentServer
    end repeat
  3. @bmfurtado bmfurtado revised this gist Apr 16, 2013. 1 changed file with 13 additions and 10 deletions.
    23 changes: 13 additions & 10 deletions cssh.applescript
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,8 @@
    #!/usr/bin/osascript

    -- Launche multiple SSH session
    -- simplified and (hopefully more readable) version of github:xgdlm/iterm2-cssh
    -- completely rewritten but inspired by github:xgdlm/iterm2-cssh

    -- retrieve command line arguments
    on run argv

    set serverList to argv
    @@ -16,8 +15,9 @@ on run argv

    set numServers to count serverList

    -- Number of horizontal splits
    set numHorizontal to (round (numServers / 2) rounding up)
    -- number of panels we should end up with
    set numHorizontal to (round (numServers ^ 0.5) rounding up)
    set numVertical to (round (numServers / numHorizontal) rounding up)

    set createdPanels to 1

    @@ -37,20 +37,23 @@ on run argv
    -- split each of the panels vertically
    repeat createdPanels times
    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}
    set createdPanels to createdPanels + 1
    repeat numVertical - 1 times
    if createdPanels is less than (count serverList)
    tell i term application "System Events" to keystroke "d" using {command down, shift down}
    set createdPanels to createdPanels + 1
    end if
    end repeat
    end repeat

    if createdPanels is greater than (count serverList) then
    tell i term application "System Events" to keystroke "w" using {command down}
    end if

    -- open ssh sessions--
    repeat with loopIndex from 1 to (count serverList)
    set currentServer to item loopIndex of serverList
    tell item loopIndex of sessions to write text "ssh " & currentServer
    end repeat

    -- introducing delay to avoid weirdness
    delay 1

    tell i term application "System Events" to keystroke "I" using {command down, shift down}

    end tell
  4. @bmfurtado bmfurtado revised this gist Apr 16, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion cssh.applescript
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ on run argv
    activate
    set myterm to (make new terminal)
    tell myterm
    launch session "distantssh"
    launch session "Default Session"

    -- create the horizontal panels
    repeat numHorizontal - 1 times
  5. @bmfurtado bmfurtado revised this gist Apr 16, 2013. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions cssh.applescript
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ on run argv
    -- Number of horizontal splits
    set numHorizontal to (round (numServers / 2) rounding up)

    set createdPanel to 1
    set createdPanels to 1

    tell application "iTerm"

    @@ -31,24 +31,24 @@ on run argv
    -- create the horizontal panels
    repeat numHorizontal - 1 times
    tell i term application "System Events" to keystroke "d" using {command down}
    set createdPanel to createdPanel + 1
    set createdPanels to createdPanels + 1
    end repeat

    -- split each of the panels vertically
    repeat createdPanel times
    repeat createdPanels times
    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}
    set createdPanel to createdPanel + 1
    set createdPanels to createdPanels + 1
    end repeat

    if createdPanel is greater than (count serverList) then
    if createdPanels is greater than (count serverList) then
    tell i term application "System Events" to keystroke "w" using {command down}
    end if

    -- open ssh sessions
    -- open ssh sessions--
    repeat with loopIndex from 1 to (count serverList)
    set theChoice to item loopIndex of serverList
    tell item loopIndex of sessions to write text "ssh " & theChoice
    set currentServer to item loopIndex of serverList
    tell item loopIndex of sessions to write text "ssh " & currentServer
    end repeat

    tell i term application "System Events" to keystroke "I" using {command down, shift down}
  6. @bmfurtado bmfurtado revised this gist Apr 16, 2013. 1 changed file with 6 additions and 11 deletions.
    17 changes: 6 additions & 11 deletions cssh.applescript
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/usr/bin/osascript

    -- Launche multiple SSH session
    -- simplified and (hopefully more readable) fork of github:xgdlm/iterm2-cssh
    -- simplified and (hopefully more readable) version of github:xgdlm/iterm2-cssh

    -- retrieve command line arguments
    on run argv
    @@ -17,7 +17,7 @@ on run argv
    set numServers to count serverList

    -- Number of horizontal splits
    set numHorizontal to (round (numServers / 2)) + 1
    set numHorizontal to (round (numServers / 2) rounding up)

    set createdPanel to 1

    @@ -29,7 +29,7 @@ on run argv
    launch session "distantssh"

    -- create the horizontal panels
    repeat numHorizontal times
    repeat numHorizontal - 1 times
    tell i term application "System Events" to keystroke "d" using {command down}
    set createdPanel to createdPanel + 1
    end repeat
    @@ -41,14 +41,9 @@ on run argv
    set createdPanel to createdPanel + 1
    end repeat

    repeat with loopIndex from 1 to createdPanel
    if loopIndex is less than or equal to (count serverList) then
    set theChoice to item loopIndex of serverList
    else
    -- remove any extra possible windows
    tell i term application "System Events" to keystroke "w" using {command down}
    end if
    end repeat
    if createdPanel is greater than (count serverList) then
    tell i term application "System Events" to keystroke "w" using {command down}
    end if

    -- open ssh sessions
    repeat with loopIndex from 1 to (count serverList)
  7. @bmfurtado bmfurtado created this gist Apr 15, 2013.
    63 changes: 63 additions & 0 deletions cssh.applescript
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    #!/usr/bin/osascript

    -- Launche multiple SSH session
    -- simplified and (hopefully more readable) fork of github:xgdlm/iterm2-cssh

    -- retrieve command line arguments
    on run argv

    set serverList to argv

    -- Print help if no servers are given
    if (count serverList) = 0
    log("usage: iterm2-cssh [user@]hostname ...")
    return
    end if

    set numServers to count serverList

    -- Number of horizontal splits
    set numHorizontal to (round (numServers / 2)) + 1

    set createdPanel to 1

    tell application "iTerm"

    activate
    set myterm to (make new terminal)
    tell myterm
    launch session "distantssh"

    -- create the horizontal panels
    repeat numHorizontal times
    tell i term application "System Events" to keystroke "d" using {command down}
    set createdPanel to createdPanel + 1
    end repeat

    -- split each of the panels vertically
    repeat createdPanel times
    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}
    set createdPanel to createdPanel + 1
    end repeat

    repeat with loopIndex from 1 to createdPanel
    if loopIndex is less than or equal to (count serverList) then
    set theChoice to item loopIndex of serverList
    else
    -- remove any extra possible windows
    tell i term application "System Events" to keystroke "w" using {command down}
    end if
    end repeat

    -- open ssh sessions
    repeat with loopIndex from 1 to (count serverList)
    set theChoice to item loopIndex of serverList
    tell item loopIndex of sessions to write text "ssh " & theChoice
    end repeat

    tell i term application "System Events" to keystroke "I" using {command down, shift down}

    end tell
    end tell
    end run