Can I run scripts when VSCode boots and closes?

Viewed 276

I'm developing on a VM and I'd like to automate booting and shutting down the VM whenever I launch VSCode into this project (over ssh).

I got around having to boot the VM by creating a script that launched the VM then VSCode. I use that to launch VSCode instead of the start menu whenever I want to work on this project. However, this solution doesn't work for shutting down the VM when I'm done.

Is there any way to accomplish this? Maybe some project setting that would execute a shutdown script on the VM when I disconnect, or some way I could hook up a script to run on my machine when VSCode closes that would shut down the VM?

Is there any way to avoid the janky startup script? Can I run a script when VSCode launches as well?

1 Answers

According to Visual Studio Code issue #10044 https://github.com/Microsoft/vscode/issues/10044, there is no way to run a script automatically from inside VSCode at startup unless you are willing to write an extension. Even if you are going to write an extension according to the API documentation https://code.visualstudio.com/api/references/activation-events for VSCode, There is no event for when shutdown occurs.

EDIT: Although it is not possible to do this within VScode alone, you could write a wrapper script when starting and exiting to to run the command.

Related