- Allows supplying arbitrary arguments as selected code
Allows jumping to error lines
In TextPad, go to Configure | Preferences. In the left-hand pane of the
Preferences window, click on "Tools". You will see an "Add" button to the
right; click that, and choose "Program" from the dropdown. When the browsing window opens, navigate to cscript.exe (usually in your windows directory or its system32 subdirectory). Select it, click open, then when the browsing window goes and you are back in "Preferences", click the "Apply" button in the lower right.
2. FIND THE TOOL IN THE LIST
Then in the big pane on the left of the Preferences window click on "Tools"
again to make sure it is selected and expanded. You should see "cscript" as a choice under "Tools"; go down to it and click it.
3. MODIFY THE TOOL TO RUN THE CURRENT FILE
If you look to the right now, you will see several options for configuring
this tool.
The topmost one, Command, will have cscript.exe in it; that's the way you
want it.
Beneath that is "Parameters". In there, insert this:
Code: Select all
//nologo "$File" $SEL
+ The "$File" is TextPad's macro for the current file name, quoted to
ensure that files with spaces run OK.
+ The $SEL allows you to select some text that you may have in the file
in a comment line and have it appended as arguments.
Initial Folder: That defaults to $FileDir, which is what you want.
4. SET UP OUTPUT CAPTURE AND ERROR REGEX
At this point cscript can be launched to run a script, but some more details
give us some nice additional features.
Going down to the middle, you may want to check "Save all documents first". I do this so I can just edit and run.
You might want to check "Prompt for Parameters". I don't bother; the $SEL macro lets me keep parameters in the script in a comment line, and I can run them just by selecting them.
If you want to capture the console output (necessary for jumping to errors) select "Capture Output". I know, I know, you already guessed that...
Where it says "Regular expression to capture output" below the checkboxes, insert this:
Code: Select all
^\(.+\)(\([0-9]+\)\, \([0-9]+\)
style in TextPad, but this actually captures 3 subexpressions: everything
from the beginning of the line up to just before a ( character; then
numerals following that up to a non-captured comma and space; then the
numerals after that. This means that if the output looks like this:
Code: Select all
C:\bin\scripts\win32shutdown.wsf(69, 11) SWbemObjectSet: Generic failure
We just need to set that up in the registers. For the File register, make
sure you have 1; for the Line register, put 2; and for the Column, put 3.
They may have defaulted to that anyway...
Press OK, and you're done.
5. RUNNING THE TOOL
You can select it from the "Tools" menu. If it's one of the first tools you
have installed, it will also have a Ctrl+n (where n is a number) shown next
to it for a keyboard shortcut.
To supply arbitrary commandline parameters to the script, you can simply insert as a commented line in the script, then select the text argument data you want to use. For example, if you want to run a script with the commandline arguments //X to start the debugger and with "C:\tmp\text file.txt" as a normal script-processed argument, you would insert a line of VBScript code with a preceding ' to comment it out like this:
Code: Select all
' //X "C:\tmp\text file.txt"