UPDATED 2023-03: We now included the Visual Studio Code preset described below in the free Docklight Scripting v2.4.11 update. 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:
- Go to Scripting > Customize / External Editor and paste the following text into the Application Control text box:
; 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
- 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:
1) 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 ensure your latest edits are already written to file, even before pressing Run Script / Shift + F5 in Docklight.)
2) Check/modify the default file encoding for .vbs files. This is can be done easiest by editing the settings.json file. E.g. for using ISO8859-1 ("latin1") encoding to support scripts with German umlauts, add the following lines to the settings.json definitions:
"[vbs]": {
"files.encoding": "iso88591"
}
...
}
As an alternative, you can always switch the currently open file from the UTF-8 default to your preferred encoding, using the toolbar on the bottom right:
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
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
Post a Comment