Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I programmatically control / script Visual Studio Code?

I use AppleScript in my Mac for automating various processes in my computer. I know that Visual Studio Code does not have an AppleScript dictionary.

Is there any way to programmatically control Visual Studio Code eg using Python or any other programming language?

As an example I would like to programmatically get the path of the frontmost document.

I know that VSC has a JavaScript API . Can I use this for automation purposes?

like image 386
organognosi Avatar asked Sep 15 '25 21:09

organognosi


1 Answers

I guess a lot of such automation / programmatic control can be done via the JavaScript extension API.

There is vscode.window.activeTextEditor, and that gives you document.fileName or document.uri for the filename, and selection.active to get you the cursor position (example).

It looks like this API allows for a lot of automation, e.g. moving cursor around, inserting text, etc.

There is vscode-ext (active fork) to write Python extensions. When you look at the code, you see that this provides a websockets bridge from JavaScript inside VSCode to Python in a separate process. This bridge could be use for controlling VSCode from some external process.

Further, I just learned about the Robot Framework / Robotic Process Automation (RPA) Framework (also with Python backend). I'm not sure but it might be helpful.

like image 191
Albert Avatar answered Sep 17 '25 19:09

Albert