我正在尝试使用所示的 iTerm 示例 here回答另一个问题。
基本上,我有大约 20 个文本文件的列表,代表来自不同服务器的报告。我想读取它们所在目录中的每个文件名,并从中构建命令目录中存在的 shell 命令,然后打开一个新的 iTerm 窗口,然后执行我构建的 shell 脚本。
我不想在一个窗口中依次运行它们,我希望它们各自在自己的窗口中执行以加快处理速度。
这就是我所拥有的,我可以非常愉快地构建 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
我收到的错误是:deltrash.sh:第 22 行:语法错误:意外的文件结尾
谁能给我指点一下吗?
最佳答案
查看iTerm
applescript examples ,类似的东西应该有效。基本上,您必须将 myterm 变量设置为新的终端实例。另请务必将 END
标记放在行首。您的脚本中未检测到它,因此出现意外的文件结尾
错误。
#!/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
关于macos - 用于打开新 iTerm 窗口并运行基于变量的命令的 OSX 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30518627/