OSAScript to open new tab and run command no longer works
Thanks for filing an issue! Please answer the questions below so I can help you.
- iTerm2 version: 3.3.0beta4
- OS version: 10.14.4
I have a script which opens up a new tab, sets its title and and optionally runs a command in it, and I use it to open up multiple tabs at once and run a command in each of them simultaneously.
It has been working just great up until 3.3.0beta4 when it stopped working - the new tabs would open but the title or command would not execute. I verified that it still works in 3.2.9, and I'm guessing changes in 3.3.0beta4 around not blocking the main thread when creating a new session could be the cause?
My script to open a new tab is named run-command-in-new-tab
and is as follows:
tab_name="$1"
shift
cmd=""
cdto="$PWD"
args="$@"
if [ -d "$1" ]; then
cdto=$(cd "$1" && pwd)
args="${@:2}"
fi
if [ -n "$args" ]; then
cmd="; $args"
fi
osascript <<EOF
tell application "iTerm"
tell current window
set newTab to (create tab with default profile)
tell current session of newTab
write text "title $tab_name; cd \"$cdto\"$cmd"
end tell
end tell
end tell
EOF
I can execute it like:
run-command-in-new-tab new-tab-title date && run-command-in-new-tab another-tab-title ls -l
In 3.2.9 it works fine, in 3.3.0beta4 I just get empty tabs and no custom title or command executed.
I tried adding a select
after creating a new tab in the script above and that improved things where some tabs it worked, but others it didn't (I tried it with opening 6 tabs and running commands and it worked for 3 of them). So that looks like that isn't the root cause of the issue, but looks like a possible regression in 3.3.0beta4.
Thanks for your help.