on run argv
— last argument should be the window title
set windowtitle to item (the count of argv) of argv as text
— all but last argument go into CLI parameters
set cliargs to “”
repeat with arg in items 1 thru -2 of argv
set cliargs to cliargs & ” ” & arg as text
end repeat
tell application “iTerm”
activate
if current window exists then
tell current window
— These commands return a tab
set newTab to (create tab with default profile)
tell the current session of newTab
set name to windowtitle
write text cliargs
end tell
end tell
else
set newWindow to (create window with default profile)
tell current window
— These commands return a tab
set newTab to (create tab with default profile)
tell the current session of newTab
set name to windowtitle
write text cliargs
end tell
end tell
end if
end tell
end run