I am trying to open multiple iterm tabs and execute commands in them using applescript. But I want to run the command and switch to another iterm window to do other stuff meanwhile. Unfortunately, the focus keeps going back to the window executing the applescript on every "create tab with default profile".
How is it possible to keep the script in that window running in the background without bringing that window to the front?
function iterm_project
osascript \
-e 'tell application "iTerm"' \
-e " tell window id \"$argv[1]\"" \
-e ' create tab with default profile' \
-e ' tell current tab' \
-e ' tell current session' \
-e " set name to \"$argv[2]\"" \
-e " write text \"cd $argv[3]\"" \
-e ' split vertically with default profile' \
-e ' end tell' \
-e ' tell second session' \
-e " set name to \"$argv[2]\"" \
-e " write text \"cd $argv[3]\"" \
-e ' split horizontally with default profile' \
-e ' end tell' \
-e ' tell third session' \
-e " set name to \"$argv[2]\"" \
-e " write text \"cd $argv[3]\"" \
-e ' end tell' \
-e ' end tell' \
-e ' end tell' \
-e 'end tell'
end
I am using a fish shell so iterm_project() will be passed three variables the first being the window id this script will be executing in. This function will be called from another function that will decide how many tabs to open and call iterm_project() continuously with same window id but different "name" "path to cd in".
-e
and all that quote escaping, learn how to write it in the form of a here document.