[英]On osx, how to open new iterm terminal tab from one script then run command in that temrinal window
[英]OSX script to open a new iTerm window and run a command based on a variable
基本上,我有一個大約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.