How do I set up an AppleScript to open a new iTerm2 tab and change the directory?
Daniel's solution somehow opens a new Window – also, the exec command
statement does not work as expected. One has to write text
instead.
Also, you have to use
launch session "Default Session"
in order to get a new tab.
The following does what you asked for:
tell application "iTerm"
make new terminal
tell the current terminal
activate current session
launch session "Default Session"
tell the last session
write text "cd ~/Downloads; clear; pwd"
end tell
end tell
end tell
If anyone in 2020 looking for answer to this, find below:
tell application "iTerm"
set newWindow to (create window with default profile)
tell current session of newWindow
write text "cd ~/Desktop; clear; pwd"
end tell
end tell