I'm trying to create a script which would open a iTerm2
window, split it into 3 panes vertically and run a few commands inside each of those panes.
Here's my attempt so far:
tell application "iTerm2"
activate
-- Create main window
create window with default profile
tell current session of current window
set name to "frontend"
write text "cd ~/Documents/frontendDir"
split vertically with default profile
end tell
tell second session of current window -- ERROR HERE
set name to "backend"
write text "cd ~/Documents/backendDir"
split vertically with default profile
end tell
tell third session of current window
set name to "apollo-server"
write text "cd ~/Documents/GitHub/apolloDir"
end tell
end tell
The first part about creating the frontend
seems to work as the window is correctly opened and the command cd ~/Documents/frontendDir
is correctly executed in it. The window is also split vertically once as I'm pretty sure it stops executing when I try to access the second pane of my window.
I'm getting this error: iTerm got an error: Can’t get session 2 of current window
Thanks in advance