3
A
回答
5
我与亚历克斯同意,使用AppleScript是最好的选择。
这是我的“iterm”脚本,我chmod作为可执行文件并将其放在我的路径中的一个目录中。我可以这样使用它:
报价封闭外壳参数:
iterm "ls -l"
传递多个CMDS运行:
iterm "calculatesomthing" "exit"
传递多个CMDS,分号separtated:
iterm "cd ~/mediaprojects; ./gitSyncAll; exit"
自封闭的bash/Applescript:
#!/bin/bash
read -r -d '' script <<'EOF'
on run argv
tell application "iTerm"
activate
set myterm to (make new terminal)
tell myterm
launch session "Default"
tell the last session
repeat with arg in argv
say arg
write text arg
end repeat
end tell
end tell
end tell
end run
EOF
echo "$script" | osascript ``-'' [email protected]
仅供参考:您可能需要删除“say”命令,我将其用作每个正在执行的cmd的远程/声音通知。我通过一堆cmds到多个自定义iTerm配置文件/外壳,平铺到一个大的纯平屏幕,以显示复杂的多DC Azure部署的状态...
PS:我添加了一个要点作为报价脚本的最后一行没有被剪切/正确粘贴给某人@https://gist.github.com/sushihangover/7563e1707e98cdf2b285
2
你最好使用AppleScript这一点。 iTerm2有一些examples脚本。这些文档有点粗俗,但这些例子应该让你知道从哪里开始。
您可以在bash脚本包裹AppleScript的字符串,然后使用osascript
启动它:
#~/bin/bash
tell application "iTerm"
# etc...
exec command "[email protected]"
然后运行该脚本很简单,只要:
./run-in-iterm.sh "echo 'hello world'"
3
我发现了official documentation,但没有想过用像SushiHangover这样的osascript包装Applescript-非常好。他的回答对我不起作用,可能是因为我使用的是最新的beta 3.0版本,所以这里有一个工作(并且简化了一点)。
#!/bin/bash
osascript - "[email protected]" <<EOF
on run argv
tell application "iTerm"
activate
set new_term to (create window with default profile)
tell new_term
tell the current session
repeat with arg in argv
write text arg
end repeat
end tell
end tell
end tell
end run
EOF
相关问题
- 1. 如何可以从命令行在Linux中执行nagios命令
- 2. 从NSIS执行命令行命令
- 3. 从命令行执行Django Shell命令
- 4. 从Python执行命令行命令
- 5. 从Perl执行命令行命令?
- 6. 在命令窗口中运行rcp时如何从命令行获取参数?
- 7. bash命令在新的命令行窗口中运行程序
- 8. 模态窗口块命令执行
- 9. python执行系统命令(窗口)
- 10. 如何从C++程序执行命令行命令
- 11. 打开一个命令窗口并从中执行一系列命令
- 12. 如何在新的命令行窗口中运行2个命令?
- 13. 如何在php中打开终端窗口并执行命令?
- 14. 如何在ruby/rails的新窗口中执行shell命令?
- 15. 从命令行执行Powershell
- 16. 从JConsole执行命令行
- 17. 如何在iPhone中执行命令行?
- 18. MFC命令窗口命令
- 19. 如何从命令行执行Scrooge?
- 20. 命令行命令的执行时间
- 21. C#运行命令不执行命令
- 22. 如何通过执行外部命令来执行vim命令?
- 23. rsa securid令牌命令行窗口
- 24. 执行命令
- 25. 执行命令
- 26. 执行命令
- 27. 在运行窗口中调用命令
- 28. Visual Studio命令窗口2010命令是否可以在脚本中执行
- 29. 无法通过在命令窗口中执行的c#提供输入命令
- 30. 从命令行最大化窗口(Keepassx2)
我同意,AppleScript是要走的路,我添加了一个Answer,它具有我使用的自封闭bash/AppleScript脚本。 – SushiHangover