Save output window content to file

Save output window content to file

2

    Jul 22, 2013#1

    I am trying to write a script that will copy the Output Window to a file for use as a log of FTP events. I have been able to copy an Output Window Tab, but it is not the tab that holds the FTP information (tab 1). It copies a new tab (tab 2) which records the script output. I execute the script while tab 1 is active, but it still uses tab 2. Here is a sample script segment that works, but I have been unable how to get tab 1 output. or, even write to tab 1. I also do not know how to close Output Window tab 2 only. Any help is appreciated.

    Code: Select all

        UltraEdit.selectClipboard(0);
        var sClipboard0 = UltraEdit.clipboardContent;
    
        nActiveClipboard = UltraEdit.clipboardIdx;
    
        UltraEdit.outputWindow.write("====================================================="); 
        UltraEdit.outputWindow.write(" Active clipboard index:   " + nActiveClipboard);
        UltraEdit.outputWindow.write("====================================================="); 
    
        UltraEdit.outputWindow.copy();
       
        UltraEdit.outputWindow.write(" Active clipboard content: " + UltraEdit.clipboardContent);
    

    6,603548
    Grand MasterGrand Master
    6,603548

      Jul 23, 2013#2

      nActiveClipboard has in your script always value 0 as you use before command UltraEdit.selectClipboard(0).

      Unfortunately there is no command to select one of the 2 output windows of UltraEdit. I have requested that as feature by email to IDM support and hope that other users do that also for increasing the priority of implementing such a command.

      Whatever output window is active on script start is accessed from within the script with the outputWindow object and its member functions.

      By default the status informations are written also to the output window resulting in clearing the active output window on script start. There is the configuration setting Show status information in output window at Advanced - Configuration - Scripting. Unchecking this option avoids printing status information of JavaScript interpreter to active output window which avoids since UltraEdit v19.10 also clearing the output window on script start. So you have to uncheck this setting and use UE v19.10 to get access to content of active output window written to the output before script started by the script.

      Note: With Show status information in output window unchecked also error messages of built-in JavaScript interpreter are suppressed and therefore you don't see any error message in active output window if the script contains any syntax error. There is a property to toggle status information printing to output window on/off from within the script, but that property is interpreted by JavaScript core engine after script started and therefore after general syntax check on script code.

      2

        Jul 23, 2013#3

        Thank you very much for your reply. I worked at it yesterday until I stumbled on this fact, so now I have confirmation that I found the only solution. I also learned that if you try to write to the output window as I sometimes do to evaluate my code, it will do the same thing. It will switch to another tab and again, I do not get the right content in the copy. I've read your posts before and thank you for all of the help you have given all who read the forums. This code will copy the active output window.

        Code: Select all

        // ----------------------------------------------------------------------------
        // Script Name:    SaveOutputWindow.js
        // Creation Date:  07/22/2013
        // Last Modified:  07/27/2013
        // Purpose:        Append Output Window to a log file, in this instance used to record FTP
        //                 messages when using the FTP Browse feature to download or upload files.
        // FunctionList:   FileExist - by IDM Forums member "Mofi" found in post
        //                             "Re: Action if file does not exist"
        //                             http://forums.ultraedit.com/viewtopic.php?f=52&t=8850#p31506
        //              GetFileIndex - by IDM Forums member "Mofi" found in post
        //                             "List of UltraEdit / UEStudio script commands and most common mistakes"
        //                             http://forums.ultraedit.com/viewtopic.php?f=52&t=4596#p26710
        // Scripts used:   header.js - This script creates a header for all open documents
        //                             Copyright (c)2007 IDM Computer Solutions, Inc.
        // ----------------------------------------------------------------------------
        
        //define variables
        var docIndex;
        var logFile;
        var lineEnd = "\r\n";
        
        // wrap in try/catch to handle any errors
        try {
        
            // set up file name
            logFile = "C:\\vision\\log\\ftp.log";
        
            // get document index in case of file being already open
            docIndex = GetFileIndex(logFile);
            if (docIndex < 0) {
                docIndex = UltraEdit.document.length;
                // create new log file if logfile does not exist
                if (FileExist(logFile) == true) {
                    UltraEdit.open(logFile);
                    // Make sure we start at the bottom of the file
                    UltraEdit.activeDocument.bottom();
                }
                else {
                    UltraEdit.newFile();
                    UltraEdit.saveAs(logFile);
                }
            }
            // if output window is not visible, make it visible
            if (UltraEdit.outputWindow.visible == false) {
                UltraEdit.outputWindow.showWindow(true);
            }
        
            // tell ultraedit to use user clipboard 8
            UltraEdit.selectClipboard(8);
        
            // copy the active output window
            UltraEdit.outputWindow.copy();
        
            // set up date and time stamp - code from http://www.w3schools.com/jsref/jsref_obj_date.asp
            var d=new Date();
            var dTime=d.toLocaleTimeString();
            var dDate=d.toDateString();
        
            // use \n instead of \r\n as line ending if log file is a Unix file
            if (UltraEdit.document[docIndex].lineTerminator == 1) lineEnd = "\n";
        
            UltraEdit.insertMode();
            if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
            else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
        
            // write log event header
            UltraEdit.document[docIndex].write("====================================================="+lineEnd);
            UltraEdit.document[docIndex].write("FTP Event Log for " + dDate + " " + dTime + lineEnd);
            UltraEdit.document[docIndex].write("====================================================="+lineEnd);
        
            // write FTP output window info to log file
            UltraEdit.document[docIndex].paste();
        
            // clear user clipboard 8 and select Windows clipboard
            UltraEdit.clearClipboard();
            UltraEdit.selectClipboard(0);
        
            // save file and leave it open in UE for review.
            if (UltraEdit.activeDocument.path != UltraEdit.document[docIndex].path) {
                UltraEdit.document[docIndex].setActive();
            }
            UltraEdit.save();
        }
        catch (err) {
            UltraEdit.outputWindow.write("This is an error: " + err.toString());
        }
        
        // Does file exist function
        function FileExist (sFileName) {
        
           // Is the required parameter passed to the function?
           if (typeof(sFileName) != "string") return false;
        
           // Is the file name an empty string?
           if (sFileName == "") return false;
        
           // Store the index of the active clipboard.
           var nActiveClipboard = UltraEdit.clipboardIdx;
        
           // Use clipboard 9 to save current output window data, but
           // before save content of clipboard 9 into string variable.
           UltraEdit.selectClipboard(9);
           var sClipboard9 = UltraEdit.clipboardContent;
           UltraEdit.outputWindow.copy();
           UltraEdit.outputWindow.clear();
        
           // Run Find in Files with an empty search string and with the passed file
           // name as file type. The search result is written to the output window.
           UltraEdit.frInFiles.regExp=false;
           UltraEdit.frInFiles.matchCase=true;
           UltraEdit.frInFiles.matchWord=false;
           UltraEdit.frInFiles.searchSubs=false;
           UltraEdit.frInFiles.unicodeSearch=false;
           UltraEdit.frInFiles.filesToSearch=0;
           UltraEdit.frInFiles.directoryStart="";
           UltraEdit.frInFiles.useOutputWindow=true;
           UltraEdit.frInFiles.ignoreHiddenSubs=false;
           UltraEdit.frInFiles.displayLinesDoNotMatch=false;
           UltraEdit.frInFiles.searchInFilesTypes=sFileName;
           UltraEdit.frInFiles.find("");
        
           // Use clipboard 8 to get search result in output window, but
           // before save content of clipboard 8 into string variable.
           UltraEdit.selectClipboard(8);
           var sClipboard8 = UltraEdit.clipboardContent;
           UltraEdit.outputWindow.copy();
        
           // Search for the passed file name in the search result.
           // If not found, i.e. returned index == -1, the file does not exist.
           var bFileFound = (UltraEdit.clipboardContent.indexOf(sFileName) < 0) ? false : true;
        
           // Restore content of clipboard 8.
           UltraEdit.clearClipboard();
           if (sClipboard8 != "") UltraEdit.clipboardContent = sClipboard8;
        
           // Restore content of the output window.
           UltraEdit.selectClipboard(9);
           UltraEdit.outputWindow.clear();
           UltraEdit.outputWindow.write(UltraEdit.clipboardContent);
        
           // Restore content of clipboard 9.
           UltraEdit.clearClipboard();
           if (sClipboard9 != "") UltraEdit.clipboardContent = sClipboard9;
        
           // Select the previous active clipboard.
           UltraEdit.selectClipboard(nActiveClipboard);
        
           // Return the result of the file existence check.
           return bFileFound;
        }
        
        function GetFileIndex (sFullNameOfFile)
        {
           // Is the passed value not a string because simply nothing passed?
           if (typeof(sFullNameOfFile) != "string")
           {
              // With UltraEdit v16.00 and later there is a property which holds active document index.
              if (typeof(UltraEdit.activeDocumentIdx) == "number") return UltraEdit.activeDocumentIdx;
              sFullNameOfFile = UltraEdit.activeDocument.path;
           }
           else if (!sFullNameOfFile.length) // It is a string. Is the string empty?
           {
              if (typeof(UltraEdit.activeDocumentIdx) == "number") return UltraEdit.activeDocumentIdx;
              sFullNameOfFile = UltraEdit.activeDocument.path;
           }
           // Windows file systems are not case sensitive. So best make all file
           // names lowercase before comparing the name of the file to search
           // for with the names of the already opened files. Users of UEX should
           // use a case sensitive file name comparison and therefore don't need
           // toLowerCase() here and in the following loop.
           var sFileNameToCompare = sFullNameOfFile.toLowerCase();
        
           // Compare the name of the file to search for with the (lowercase) file
           // names of all already opened files. Return the document index of the
           // file already opened when found.
           for (var nDocIndex = 0; nDocIndex < UltraEdit.document.length; nDocIndex++)
           {
              if (UltraEdit.document[nDocIndex].path.toLowerCase() == sFileNameToCompare)
              {
                 return nDocIndex;
              }
           }
           return -1; // This file is not open.
        }
        

        6,603548
        Grand MasterGrand Master
        6,603548

          Jul 27, 2013#4

          I reviewed and improved the code of your script in your second post.

          I could not see the effect of switching the current output window tab by writing something from within the script to output window.

          The above script SaveOutputWindow.js to copy and save content of active output window into a file works only with UE v19.10 or UES v13.10 or any later version of UE/UES and with configuration setting Show status information in output window being turned off for the reasons I wrote in my first post.