8

Question

I've seen lots of ways to open a new terminal "tab/pane/view" using an external Terminal app like the macOS Terminal app or iTerm using a shell script or Apple Script but is it possible to write a script that opens up two different VS Code integrated terminal "tabs/panes/views" in the current workspace?

My Use Case

I'm starting my application and I want the client side logs and server side logs to open in separate integrated terminal windows side-by-side when the build completes.

What I'm Not Looking For

I've seen lots of ways to open a new VSCode terminal tab from within the VSCode settings/UI/key commands/command palette but I specifically need a way to do it using a shell script.

Thanks!

Joshua Dyck
  • 2,113
  • 20
  • 25
  • have you found a solution ? – Ced Feb 14 '22 at 15:50
  • @Ced, At the moment I'm just using VSCode Tasks which give full access to opening terminal panes inside VSCode. It not as powerful or flexible as using the CLI but it works for now. See https://code.visualstudio.com/docs/editor/tasks#_output-behavior – Joshua Dyck Feb 14 '22 at 19:14

1 Answers1

0

I've just faced same problem and I found one possible solution that may work for you. In my case I run this script through npm run my_scenario that executes something on one side terminal and comes back to execute react-scripts start or whatever.

To achive that I used xdotool to simulate shortcut keypresses.

#!/bin/bash
active_window_id=$(xdotool search --onlyvisible --class "code" | tail -1)
xdotool windowactivate "$active_window_id" && xdotool key ctrl+shift+5
sleep 1
new_terminal_tab_id=$(xdotool search --onlyvisible --class "terminal" | tail -1)
xdotool type --window "$new_terminal_tab_id" "echo Hello, World!"
#return to the previous terminal
xdotool windowactivate "$active_window_id" 

I don't really like this solution, if you'll find more elegant way please let me know.

b.gorelkin
  • 141
  • 4