OSX脚本打开一个新的iTerm窗口,并基于变量运行命令



我正在尝试使用这里显示的iTerm示例来回答另一个查询。

基本上我有一个大约20个文本文件的列表,代表来自不同服务器的报告。我想读取它们所在目录中的每个文件名,并从中构建一个存在于命令目录中的shell命令,然后打开一个新的iTerm窗口,然后执行我构建的shell脚本。

我不想在一个窗口一个接一个地运行它们,我希望它们每个都在自己的窗口中执行,以加快处理速度。

这就是我所拥有的,我可以构建shell脚本名称并非常高兴地存储在foo中,似乎我也可以打开新的term窗口,但它正在让它接受$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: line 22:语法错误:unexpected end of file

谁能给我指点一下吗?

看看iTerm的applescript示例,类似的东西应该可以工作。基本上,您必须将myterm变量设置为新的终端实例。也一定要把END标记在线的开始。在您的脚本中没有检测到它,因此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

相关内容

  • 没有找到相关文章

最新更新