繁体   English   中英

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

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

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

基本上,我有一个大约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 示例 ,类似的东西应该起作用。 基本上,您必须将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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM