如何一键启动多个集成终端面板?
How can I start multiple integrated terminal panels with a click?
在 Visual Studio 代码中,我希望能够按下一个按钮或 运行 一个命令来创建多个终端面板和 运行 命令。
这在处理存储在经常卸载的驱动器中的代码时尤其有用,因为每次加载它时都必须启动几个终端并导航到正确的目录。
可能吗?
在 Mac 上,我们可以利用 AppleScript 的强大功能来完成此任务。
首先,我们需要添加一个按键来创建一个新的终端实例:
{ "key": "cmd+n", "command": "workbench.action.terminal.new",
"when": "terminalFocus" }
其次,我们创建一个 AppleScript,如下所示:
tell application "Visual Studio Code" to activate
tell application "System Events"
# Term 1
keystroke "`" using control down
keystroke "cd path/number/1"
keystroke return
# Term 2
keystroke "n" using command down
keystroke "cd path/number/2"
keystroke return
# Term 3
keystroke "n" using command down
keystroke "cd path/number/3"
keystroke return
# End
keystroke "`" using control down
end tell
最后,我们使用以下命令添加一个 VSC 任务:
osascript ./my_script.scpt
然后只是 运行 任务。
我希望有人会觉得这有用。
在 Visual Studio 代码中,我希望能够按下一个按钮或 运行 一个命令来创建多个终端面板和 运行 命令。
这在处理存储在经常卸载的驱动器中的代码时尤其有用,因为每次加载它时都必须启动几个终端并导航到正确的目录。
可能吗?
在 Mac 上,我们可以利用 AppleScript 的强大功能来完成此任务。
首先,我们需要添加一个按键来创建一个新的终端实例:
{ "key": "cmd+n", "command": "workbench.action.terminal.new",
"when": "terminalFocus" }
其次,我们创建一个 AppleScript,如下所示:
tell application "Visual Studio Code" to activate
tell application "System Events"
# Term 1
keystroke "`" using control down
keystroke "cd path/number/1"
keystroke return
# Term 2
keystroke "n" using command down
keystroke "cd path/number/2"
keystroke return
# Term 3
keystroke "n" using command down
keystroke "cd path/number/3"
keystroke return
# End
keystroke "`" using control down
end tell
最后,我们使用以下命令添加一个 VSC 任务:
osascript ./my_script.scpt
然后只是 运行 任务。
我希望有人会觉得这有用。