[英]OSX script to open a new iTerm window and run a command based on a variable
I am trying to use the iTerm example shown here in answer to another query. 我正在尝试使用此处显示的iTerm示例来回答另一个查询。
Basically I have a list of about 20 text files representing reports from different servers. 基本上,我有一个大约20个文本文件的列表,它们代表来自不同服务器的报告。 I want to read each file name in the directory they live in and from that build a shell command that exists in a commands directory, then open a new iTerm window and then execute that shell script that I built.
我想读取它们所在目录中的每个文件名,并从中构建一个存在于命令目录中的shell命令,然后打开一个新的iTerm窗口,然后执行我构建的shell脚本。
I don't want to run them all in one window one after the other, I want them each to execute in their own window to speed up the processing. 我不想在一个窗口中一个接一个地运行它们,而是希望它们每个都在自己的窗口中执行以加快处理速度。
Here is what I have, I can build the shell script name and store in foo quite happily and it seems I can open the new iTerm window OK too, but it is getting it to accept $foo as the command to be run I am having trouble with. 这就是我所拥有的,我可以很高兴地构建shell脚本名称并将其存储在foo中,似乎我也可以打开新的iTerm窗口,但是它正在接受$ foo作为要运行的命令麻烦了。
#!/bin/sh
FILES=/Volumes/reporter/uplod/lists/*
# eg each filename is of the type <path>/X07QXL29.txt
for f in $FILES
do
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"
tell the first terminal
tell myterm
launch session "Default Session"
tell the last session
write text "$foo"
write text "\n"
end tell
end tell
end tell
END
done
The error I am getting is:deltrash.sh: line 22: syntax error: unexpected end of file 我得到的错误是:deltrash.sh:第22行:语法错误:文件意外结束
Can anyone please give me a pointer? 任何人都可以给我指点吗?
Looking at iTerm
applescript examples , something like that should work. 查看
iTerm
applescript 示例 ,类似的东西应该起作用。 Basically you have to set myterm
variable to new terminal instance. 基本上,您必须将
myterm
变量设置为新的终端实例。 Also be sure to put END
marker at the beginning of line. 另外,请务必在行首放置
END
标记。 It is not detected in your script, hence unexpected end of file
error. 您的脚本中未检测到该错误,因此
unexpected end of file
错误。
#!/bin/sh
FILES=/Volumes/reporter/uplod/lists/*
# eg each filename is of the type <path>/X07QXL29.txt
for f in $FILES
do
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 tell
END
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.