0

I do the same thing every morning (or whenever I want to reboot) & would like a way to automate it.  Here are the steps.  (I don't want anything to run in the background/daemon because I need to see the output):

  1. Open Windows Terminal (PowerShell)
  2. Change path to <dir>
  3. Run an npm command: npm run <command>
  4. Open tab 2
  5. change path to <dir>
  6. run another npm command: npm run <command2>
  7. open tab 3
  8. change to <dir>

As you can see, this can become quite repetitive.  I was trying to think off the top of my head the best way to automate this & I can't think of a good way.

1 Answers1

0

You can either create one batchfile that creates new batch files on the fly and executes them, or precreate the batchfiles for each tab, and then create one batchfile that starts each batchfile.

For this example, I'm going to assume we're creating the separate batchfiles in C:\Scripts.

script1.cmd:

cd /d C:\SomePath
npm run MyCommand

And so on for the other ones.

Then, the main script:

main.cmd:

cd /d C:\Scripts
wt -w 0 nt script1.cmd
wt -w 0 nt script2.cmd
wt -w 0 nt script3.cmd

if you get the error that wt is not a program, add its path. For example:

"C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.21.10351.0_x64__8wekyb3d8bbwe\wt"

Now, if you start main.cmd it will open a windows terminal instance with 3 tabs and executes the cmd scripts in it. If for any reason you already have a windows terminal open at this point, that window will be used. Remove the -w 0 parameter from the first instance if you always want these in its own window.

The last bit is starting the main.cmd. You can use task scheduler for this, or put a shortcut to this file in your shell:startup

LPChip
  • 66,193