IDM PowerTips
UltraEdit/UEStudio scripting access to the output window
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 see our UltraEdit scripting power tip.
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:
The outputWindow Object Commands include the following: clear, copy, showOutput, showWindow, visible, write
Clears contents of output window.
Parameters: (boolean) true/false
Example usage:
Copies contents of output window to active clipboard.
Parameters: none
Example usage:
Determines visibility of output from active script. If the output window is not visible, and this is true, output window visibility will be toggled to support this.
Parameters: (boolean) true/false
Example usage:
UltraEdit.outputWindow.showOutput=false;
Determines visibility of all status information in output window (script name, success/failure of script, and errror information).
Parameters: (boolean) true/false
Example usage:
Toggles visibility of output window.
Parameters: (boolean) true/false
Example usage:
visible
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:
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:
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”.
ProductReport.js
//This script requires UltraEdit v13.10 orUEStudio v6.30 or any later.
//Get user input
var findStr;
var x = 0;
var lineNum;
var ordersArr = new Array();
//Clear the output window, make it visible and disable status information.
UltraEdit.outputWindow.showStatus=false;
UltraEdit.outputWindow.clear();
if (UltraEdit.outputWindow.visible == false) {
UltraEdit.outputWindow.showWindow(true);
}
//Make sure we start at the beginning of the file
UltraEdit.activeDocument.top();
// prompt for the search value
findStr = UltraEdit.getString(“Please Enter a Product ID”,1);
UltraEdit.outputWindow.write(“”);
UltraEdit.outputWindow.write(“— Search String —“);
UltraEdit.outputWindow.write(“You searched for \”” + findStr + “\””);
UltraEdit.outputWindow.write(“”);
UltraEdit.outputWindow.write(“— Line Numbers —“);
UltraEdit.activeDocument.findReplace.find(findStr);
//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);
}
UltraEdit.outputWindow.write(“”);
UltraEdit.outputWindow.write(“— Total Orders —“);
UltraEdit.outputWindow.write(“Total for \”” + findStr + “\” is: ” + x );
UltraEdit.outputWindow.write(“”);
UltraEdit.outputWindow.write(“— Order Data —“);
//Output values in array
for (var i = 0; i < ordersArr.length; i++) {
UltraEdit.outputWindow.write(ordersArr[i]);
}
UltraEdit.outputWindow.write(“”);
UltraEdit.outputWindow.write(“”);
//copy contents of output window
UltraEdit.outputWindow.copy();
If you need help adding a script to the scripts dialog, and executing it, please see our UltraEdit scripting power tip.
OrderExport1.csv
John,Doe,120 Jefferson St.,Riverside,NJ,08075,3,PRD-001
Mike,Pennington,123 Hickory Lane,Fairfield,OH,45014,1,PRD-002
John,Boyd,1234 East Main St.,Tau,NJ,08076,10,PRD-002
Raymond,Boltz,5555 Miami Ave,Wauneke,SD,92341,5,PRD-001
Michael,Blankman,786 Orlando Dr.,SomeTown,SD,00298,1,PRD-002
Michael,Smith,98989 W Washington Circle,Chicago,IL,86790,2,PRD-001
After you have added the script to the scripts dialog, click on the scripting menu and execute the ProductReport.js.
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.