gpt4 book ai didi

iterm - 如何从命令行在 iTerm 窗口中执行命令?

转载 作者:行者123 更新时间:2023-12-04 00:26:47 61 4
gpt4 key购买 nike

如何从命令行运行 iTerm session ,传入要在 iTerm 窗口中执行的命令?

xterm 模拟是 -e ,即

xterm -e sleep 10

最佳答案

我同意 Alex,使用 AppleScript 是最好的方法。

这是我的“iterm”脚本,我将其 chmod 作为可执行文件并将其放在我路径中的目录中。我可以这样使用它:

引用封闭的 shell 参数:

iterm "ls -l" 

传递多个 cmds 来运行:
iterm "calculatesomthing" "exit"

传递多个 cmds,以分号分隔:
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 ``-'' $@

仅供引用:您可能想要删除“say”命令,我将其用作正在执行的每个 cmd 的远程/声音通知。我将一堆 cmds 传递给多个自定义 iTerm 配置文件/ shell ,这些配置文件/ shell 被平铺到一个大平面屏幕上,以显示复杂的多 DC Azure 部署的状态......

PS:我添加了一个要点,因为脚本最后一行中的引号没有为某人正确剪切/粘贴@ https://gist.github.com/sushihangover/7563e1707e98cdf2b285

关于iterm - 如何从命令行在 iTerm 窗口中执行命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32675804/

61 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com