Last active
August 29, 2015 14:01
-
-
Save dtudury/7d0261f63cd7e1e54c7c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/osascript | |
-- run as something like `./run_in_panes.scpt "echo a" "echo b"` | |
on run argv | |
set numCmds to count of argv | |
set numCols to round numCmds ^ 0.5 rounding up | |
set numRows to round numCmds / numCols rounding up | |
launch "iTerm" | |
tell application "iTerm" | |
activate | |
set myterm to (make new terminal) | |
tell myterm | |
launch session "Default Session" | |
tell application "System Events" to keystroke "=" using {option down, command down} -- zoom | |
repeat with i from 1 to numCmds | |
set cmd to item i of argv | |
set rowIndex to round (i - 1) / numCols rounding down | |
set colIndex to (i - 1) mod numCols | |
set hasMoreRows to rowIndex < numRows - 1 | |
set isFirstCol to colIndex = 0 | |
set isLastCol to colIndex = numCols - 1 | |
set hasMoreCols to colIndex < numCols - 1 | |
set hasMoreHostNames to i < numCmds | |
if isFirstCol and hasMoreRows | |
tell application "System Events" to keystroke "D" using command down --split horizontally | |
tell application "System Events" to keystroke (ASCII character 30) using {option down, command down} -- move up | |
end if | |
delay 0.2 | |
tell the current session to write text cmd | |
if hasMoreCols and hasMoreHostNames | |
tell application "System Events" to keystroke "d" using command down -- split vertically | |
else if isLastCol and hasMoreRows | |
tell application "System Events" to keystroke (ASCII character 31) using {option down, command down} -- move down | |
end if | |
end repeat | |
end tell | |
end tell | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment