Split window programmatically with iTerm?
Solution 1:
You can easily call this from iTerm2 directly to simulate pressing ⌘D:
osascript -e 'tell application "System Events" to key code 2 using command down'
For this to work you want to start the programs in background, since otherwise you cannot run osascript
:
some-command &
osascript -e '…'
From there on you'll land in a new iTerm2 window, so you need to use the write text
option in AppleScript to run further shell commands. See here for more: How do I set up an AppleScript to open a new iTerm2 tab and change the directory?
Solution 2:
the answer here is a bit outdated.. here is an example script that does somethign similar:
tell application "iTerm"
tell current window
-- create a tab for background db stuff
create tab with default profile
tell current session
write text "mongod &"
write text "redis-server &"
end tell
close current tab
-- create tab to run aioc server
create tab with default profile
tell current session
write text "title server"
write text "aactivate"
write text "arunserver"
-- split tab vertically to run scheduler
split vertically with default profile
end tell
-- run scheduler
tell last session of last tab
write text "title scheduler"
write text "aactivate"
write text "ascheduler"
-- split tab vertically to run main controller
split vertically with default profile
end tell
-- run main_controller
tell last session of last tab
write text "title main_controller"
write text "aactivate"
write text "amain_controller"
-- split tab vertically to run aggregator
split vertically with default profile
end tell
tell last session of last tab
write text "title aggregator"
write text "aactivate"
write text "aggregator"
end tell
end tell
end tell