The following works to open two tabs in iTerm 2.
I can't seem to figure out how to get this to using split panes instead.
I've tried applying what I see on several forums, but it never works. Could someone point me in the right direction?
osascript <<-eof
tell application "iterm"
set myterm to (make new terminal)
tell myterm
launch session "Default session"
tell the last session
set name to "Server"
write text "cd $projectsFolder"
end tell
launch session "Default session"
tell the last session
set name to "Console"
write text "cd $projectsFolder"
end tell
end tell
end tell
eof
iTerm2 allows you to divide a tab into many rectangular "panes", each of which is a different terminal session. The shortcuts cmd-d and cmd-shift-d divide an existing session vertically or horizontally, respectively. You can navigate among split panes with cmd-opt-arrow or cmd-[ and cmd-].
The Split Panes feature allows you to divide a tab into multiple rectangular panes, each of which is a unique terminal session.
With the new nightly build it is quite nice. It seems to be missing in the public version, although it was implemented about a year ago: Source - AppleScriptTest.m
tell application "iTerm"
activate
select first terminal window
# Create new tab
tell current window
create tab with default profile
end tell
# Split pane
tell current session of current window
split vertically with default profile
split vertically with default profile
end tell
# Exec commands
tell first session of current tab of current window
write text "cd ~/Developer/master-node"
write text "coffee"
end tell
tell second session of current tab of current window
write text "gulp w"
end tell
tell third session of current tab of current window
end tell
end tell
I had to search way too long for this, so maybe I can help somebody out with this (probably myself in a couple of weeks), because this was one of the first things I found. This solution even works with activated focus-follows-mouse, which is missing in the other answers.
As Dom pointed out, in the new 2.9 beta builds, the other answers won't work anymore. I was frustrated by not being able to automated this so I wrote a teamocil compatible command line tool that does exactly this:
https://github.com/TomAnthony/itermocil
It allows you to write YAML files for pre-configured sets of windows and panes, which can run pre-defined sets of commands for the given project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With