Home > Blockchain >  Run two or more apps via powershell with one command
Run two or more apps via powershell with one command

Time:10-07

this is my `user_profile.ps1' file with my alias list

# some data here

Set-alias idea 'C:\users\user\appdata\local\jetbrains\toolbox\apps\idea-c\ch-0\213.5744.223\bin\idea64.exe'
Set-Alias obsidian 'C:\Users\user\AppData\Local\Obsidian\Obsidian.exe'
Set-Alias brave 'C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe'

# and there

is possible to create "super alias" for this three (or more) apps to run it with one alias like when I type something like superalias and this run three (or more) apps. Maybe you know or other possibility instead of Set-Alias

P.S. this doesn't work:

Set-Alias superalias 'C:\users\user\appdata\local\jetbrains\toolbox\apps\idea-c\ch-0\213.5744.223\bin\idea64.exe', 'C:\Users\user\AppData\Local\Obsidian\Obsidian.exe', 'C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe'

CodePudding user response:

An alias in PowerShell can only refer to one other command name or path - it is simply an alternative (usually shorter) name for another command.

In order to invoke multiple commands you need a function (adjust the name as needed):

function superalias { 
  & 'C:\users\user\appdata\local\jetbrains\toolbox\apps\idea-c\ch-0\213.5744.223\bin\idea64.exe'
  & 'C:\Users\user\AppData\Local\Obsidian\Obsidian.exe'
  & 'C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe'
}

Note the need to use &, the call operator, to invoke the external programs, which is a syntactic necessity because their paths are quoted (the same would apply if the paths contained variable names or expressions).

These external programs will launch sequentially, and any among them that are console applications will run synchronously, i.e. block further execution until they exit.

  • Related