OSX script to open a new iTerm window and run a command based on a variable OSX script to open a new iTerm window and run a command based on a variable shell shell

OSX script to open a new iTerm window and run a command based on a variable


Looking at iTerm applescript examples, something like that should work. Basically you have to set myterm variable to new terminal instance. Also be sure to put END marker at the beginning of line. It is not detected in your script, hence unexpected end of file error.

#!/bin/shFILES=/Volumes/reporter/uplod/lists/*# eg each filename is of the type <path>/X07QXL29.txtfor f in $FILESdo  foo="del"  foo+=${f:32:1}  foo+=${f:36:2}  foo+=".sh"  # foo is now for example del729.sh using the above comment as the filename  # foo is the command I will want to run in its own new window  osascript <<END    tell application "iTerm"        set myterm to (make new terminal)        tell myterm            launch session "Default Session"            tell the last session                write text "$foo"                write text "\n"            end tell        end tell    end tellENDdone