如何使用osascript打开Iterm2并运行脚本?

问题描述 投票:0回答:1

目前,我有一个

sh
文件,我用它来运行这样的脚本:

osascript -e "tell application \"Terminal\" to do script \"cd $PWD && npm run build:watch\""
osascript -e "tell application \"Terminal\" to do script \"cd $PWD && firebase emulators:start --inspect-functions\""

这在默认终端下工作得很好。但是,我如何用 Iterm2 替换它呢?我似乎无法在网上找到任何答案。

如果我用

Terminal
替换
Iterm2
,我会收到此错误:

29:38: syntax error: A “script” can’t go after this identifier. (-2740)
29:38: syntax error: A “script” can’t go after this identifier. (-2740)
terminal iterm2 iterm osascript
1个回答
0
投票

我的工作示例如下:

osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to tell current session of current window to write text "echo \"WOW! It works\""'

因此,选项“-e”之后的每个块都是您想要执行的实际命令。

  • “告诉应用程序“iTerm”激活”-> 打开 iTerm 并将其带到前面
  • '告诉应用程序“iTerm”告诉当前窗口的当前会话写入文本“echo”WOW!它有效""' -> 确实使您打开的 iTerm 中的当前会话执行给定的命令(echo“哇!它有效”在这种情况下)

希望有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.