vscode-execute-command is a Visual Studio Code extension that allows you to execute any Visual Studio Code command by calling a URL. This can help automate tasks or integrate with other tools.
- Execute Visual Studio Code commands using a URL.
- Secure the execution with a token stored in Visual Studio Code's secret storage.
- Optional notifications upon successful command execution or when an error occurs.
- Set or update the token through a command in the command palette.
- Clone the repository.
- use
vsce packageto create a VSIX file. - use
code --install-extension vscode-execute-command-$VERSION.vsixto install the extension. - Open the command palette (Ctrl+Shift+P or Cmd+Shift+P), and run the "Set token for vscode-execute-command" command to set a token that will be used for secure communication.
To execute a command using a URL, follow this format:
vscode://mattorp.vscode-execute-command?cmd=<command>&token=<token>[¬ify=<notify>]Replace <command> with the command you want to execute, <token> with the token you set earlier, and <notify> with one of the following values (optional):
true: Show a notification upon successful execution and when an error occurs.error: Show a notification only when an error occurs.
vscode://mattorp.vscode-execute-command?cmd=workbench.action.files.newUntitledFile&token=mysecrettoken¬ify=trueor
vscode://mattorp.vscode-execute-command?cmd=workbench.action.files.newUntitledFile&token=mysecrettoken¬ify=errorAs an example, you can open the URL using the command line to trigger the command, by using one of the following methods depending on your operating system:
- Windows: Open Command Prompt and run
start "vscode://mattorp.vscode-execute-command?cmd=<command>&token=<token>¬ify=<notify>". - macOS: Open Terminal and run
open "vscode://mattorp.vscode-execute-command?cmd=<command>&token=<token>¬ify=<notify>". - Linux: Open Terminal and run
xdg-open "vscode://mattorp.vscode-execute-command?cmd=<command>&token=<token>¬ify=<notify>".
You can call the URL from any application that supports opening URLs, such as a browser or a script, and which can reach the Visual Studio Code instance.
To set or update the token for secure communication, open the command palette (Ctrl+Shift+P or Cmd+Shift+P) and run the "Set token for vscode-execute-command" command.
Please note that this extension relies on the availability of the SecretStorage API in Visual Studio Code, which is only available in version 1.54.0 or newer.