Apple - open new tab in iTerm and execute command there
Use tell session -1 of current terminal to write text "pwd"
:
activate application "iTerm"
tell application "System Events" to keystroke "t" using command down
tell application "iTerm" to tell session -1 of current terminal to write text "pwd"
osascript \
-e 'tell application "iTerm" to activate' \
-e 'tell application "System Events" to tell process "iTerm" to keystroke "t" using command down' \
-e 'tell application "System Events" to tell process "iTerm" to keystroke "ls"' \
-e 'tell application "System Events" to tell process "iTerm" to key code 52'
As of at least macos Mojave, iTerm 3.2.8, if you run:
$ open -a iTerm .
It will add it as a tab to the current window.