Skip to main content

Visual Studio Code is a great editor for Docklight scripts

UPDATED 2023-02: We now included the Visual Studio Code preset described below in our update v2.4.8. See the following link for a preview: Docklight Scripting Preview Download. This also fixes the CPU load problem that came up with v2.4.5.

- The original post from January, with some improvements concerning the VS Code editor integration -

Let's start this new year with a great tip for anyone who writes his/her own Docklight scripts to automate things.




Docklight's built-in script editor is very basic by design and we never felt we should add the weight of a fully-fledged code editor to Docklight. Instead, Docklight Scripting offers you to integrate your favorite code editor via the menu Scripting > Customize / External Editor .

Now, for many years Notepad++ has been the Docklight default and my go-to solution for any script editing. But things changed last year once I tried Visual Studio Code - I was immediately won over.

One of the many benefits of Visual Studio Code is its well-documented Command Line Interface.

So here is how to explain Docklight Scripting about Visual Studio Code:
; Visual Studio Code
; See https://code.visualstudio.com/docs/editor/command-line for the excellent Command Line Interface (CLI)
; Adjust this path to the actual location of your VS Code installation:
path=C:\Users\MyUserFolder\AppData\Local\Programs\Microsoft VS Code
open: code --goto "%FILE%":%LINE%
goto: code --goto "%FILE%":%LINE%
save: sendkeys ^s save: sleep 200
close: endtask
You need to adjust the path= line of course and put the actual location of your Visual Studio Code installation there. If in doubt, search for the file Code.exe on your C:\ drive.


  • Installing a dedicated VS Code extension for VB Script / .vbs files will give you additional syntax highlighting and auto-completion benefits.


  • Make the following adjustment in the VS Code Settings:
Change Files: Auto Save to onFocusChange.



In the settings.json file this looks like this:
"files.autoSave": "onFocusChange" 
(In Docklight's External Editor configuration we already defined that Docklight sends a Ctrl+S 'Save' keystroke to VS Code and waits 200 milliseconds before reading the script. The "onFocusChange" is simply an additional way to insure your latest edits are already written to file, even before pressing Run Script / Shift + F5 in Docklight.)

Once your setup is correct, Docklight launches VS Code when you click the Open in External Editor link next to Docklight’s script view. If your script produces an error during execution, Docklight will point you to the error location in the VS Code editor, too.

We really hope the above tips can provide a nice upgrade to your Docklight Scripting environment. Of course, if you have any suggestions about how to even better adjust Docklight and VS Code, we’d be happy if you could share your insights!

Thanks for your support and best success with your own code.

Oliver Heggelbacher

- From the Docklight Developers -

www.docklight.de

Comments