运行 shell ITerm2 中的命令在完成后没有关闭选项卡
Running shell commands in ITerm2 without tab closing after completion
可能是我弄错的一个小语法问题,但在 ITerm2 documentation 中找不到解决方案。我想创建一个 applescript 来打开一个带有三个选项卡的 ITerm window,每个 运行ning 各种 shell 命令(ls、cd、echo 等),其余选项卡在这些命令有 运行 之后打开。打开选项卡部分工作正常,但似乎只要命令 运行,选项卡就会关闭(如果我不提供任何命令,选项卡将保持打开状态。)对于我的脚本:
tell application "iTerm2"
create window with default profile
tell current window
create tab with default profile command "echo abc"
create tab with default profile
end tell
end tell
我应该放什么而不是 "echo abc" 以便回显命令将 运行 在选项卡中,但给我留下一个光标让我输入更多命令而不是立即关闭选项卡之后呢?
不使用 create tab ... command
,而是使用单独的 write text
命令。例如,这是我用来打开终端到特定目录的脚本:
tell application "iTerm"
create window with default profile
tell current session of current window
write text "cd " & directory & "; clear"
end tell
end tell
使用 whereswalden 建议的 "write text" 我确定了以下方法,效果很好:
tell application "iTerm2"
create window with default profile
tell current window
tell current session
write text "echo abc"
end tell
create tab with default profile
tell current session
write text "ls -la"
end tell
create tab with default profile
tell current session
write text "cd mydir"
end tell
end tell
end tell
可能是我弄错的一个小语法问题,但在 ITerm2 documentation 中找不到解决方案。我想创建一个 applescript 来打开一个带有三个选项卡的 ITerm window,每个 运行ning 各种 shell 命令(ls、cd、echo 等),其余选项卡在这些命令有 运行 之后打开。打开选项卡部分工作正常,但似乎只要命令 运行,选项卡就会关闭(如果我不提供任何命令,选项卡将保持打开状态。)对于我的脚本:
tell application "iTerm2"
create window with default profile
tell current window
create tab with default profile command "echo abc"
create tab with default profile
end tell
end tell
我应该放什么而不是 "echo abc" 以便回显命令将 运行 在选项卡中,但给我留下一个光标让我输入更多命令而不是立即关闭选项卡之后呢?
不使用 create tab ... command
,而是使用单独的 write text
命令。例如,这是我用来打开终端到特定目录的脚本:
tell application "iTerm"
create window with default profile
tell current session of current window
write text "cd " & directory & "; clear"
end tell
end tell
使用 whereswalden 建议的 "write text" 我确定了以下方法,效果很好:
tell application "iTerm2"
create window with default profile
tell current window
tell current session
write text "echo abc"
end tell
create tab with default profile
tell current session
write text "ls -la"
end tell
create tab with default profile
tell current session
write text "cd mydir"
end tell
end tell
end tell