UltraEdit/UEStudio scripting access to the output window

The UltraEdit/UEStudio scripting engine is designed to make the automation of your tasks easier. Simply stated, it is all about automation. When you automate your tasks, you may require feedback. For example, you may need to know whether or not the task succeeded, or you may need to pull quick reports based on data in your open files. The possibilities are endless.

The scripting engine provides you access to the built in Output window giving you the ability to generate and retrieve feedback from your script.

UltraEdit/UEStudio Scripting Access to the Output Window

If you are not yet familiar with the scripting functionality in UltraEdit/UEStudio, please click here to view the introduction to scripting Power Tip.

Output Window Commands

The scripting engine is built on a JavaScript framework, the outputWindow commands are therefore a JavaScript array object which is a property of the UltraEdit application object.

Unless other parameters are noted, the Output Window Object commands are generally invoked using the following format:

Returns a BOOLEAN value indicating if output window is visible. Note, this is a READ ONLY property it does not control the behavior of the output window.

Example usage:

var isVisible = UltraEdit.outputWindow.visible;

write

Write specified text to output window. This only supports writing one line at a time and may not include line terminators.

Parameters: (String) Text to write in quotes ("")

Example usage:

UltraEdit.outputWindow.write("This is a test.");

Output Window Commands Sample Script

There are many instances in which you may need access (programmatically) to the ouput window. To demonstrate some of the capabilities, we have created a sample script that will find the instances of a Product ID number (in a CSV file) and generate a report (in the output window) and copy it to the clipboard.

This type of application of the output window functionality is especially useful when you need to analyze data from a text file, but do not wish to modify the actual file/data.

The primary Output Window Object commands used are "write" and "copy".

//loop to end of file
while (!(UltraEdit.activeDocument.isEof())) {
if (UltraEdit.activeDocument.isFound()) { //get the line number that findStr is found on
lineNum = UltraEdit.activeDocument.currentLineNum; //store line in array entry, but without line termination
UltraEdit.activeDocument.key("HOME"); /* If configuration setting >Home Key Always Goto Column 1<
is not enabled, the cursor could be not at start of the
line, if the line starts with spaces or tabs. */
if (UltraEdit.activeDocument.isColNumGt(1)) {
UltraEdit.activeDocument.key("HOME");
}
UltraEdit.activeDocument.startSelect();
UltraEdit.activeDocument.key("END");
ordersArr[x]= UltraEdit.activeDocument.selection;
UltraEdit.activeDocument.endSelect(); //output the line findStr is on
UltraEdit.outputWindow.write("Found \"" + findStr + "\" on line: " + lineNum); //increment count
++x;
} else {
UltraEdit.activeDocument.bottom();
break;
}
UltraEdit.activeDocument.findReplace.find(findStr);
}

After you have added the script to the scripts dialog, click on the scripting menu and execute the ProductReport.js.

When prompted by the Data Input, type in the product ID number. The number we are using for our example is PRD-001.

After the script has executed, you will see the "report" generated in the output window. Furthermore, if you open a new edit window and PASTE (CTRL + V), you will see the contents of the output window was pasted into the new edit window.