简体   繁体   English

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

[英]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.

相关问题 在osx上,如何从一个脚本打开新的iterm终端选项卡,然后在该临时窗口中运行命令 - On osx, how to open new iterm terminal tab from one script then run command in that temrinal window OSX shell脚本打开新的终端窗口并运行程序 - OSX shell script open new terminal window and run program 在ITerm2中打开新选项卡,然后使用zsh脚本在其中运行命令 - Open new tab in ITerm2 and run commands there with zsh script 是否有 osx 命令或 osx 脚本可以安排按日期和时间运行命令(例如“open /Applications/iTunes.app”)30 秒? - Is there an osx command or osx script that can schedule to run a command (eg "open /Applications/iTunes.app") by date and time by 30 seconds? 如何从命令行(OSX iterm)调用aquamacs来打开给定行号的文件? - How can I invoke aquamacs from command line (OSX iterm) to open a file at a given line number? 从Perl脚本打开新终端窗口并执行SSH命令 - Open New Terminal Window from Perl Script and Execute SSH command 在OSX上的tkinter:打开新窗口而不是选项卡 - tkinter on OSX: open new window instead of tab 使用OSX defaults命令更改Iterm2设置 - Change Iterm2 settings with OSX defaults command 有没有办法打开一系列新的终端窗口,并在单个脚本中运行命令? - Is there a way to open a series of new terminal window, and run commands in a single script? osx-启动iTerm时运行命令 - osx - Running a command when iTerm is launched
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM