Finding the Command Output window

Finding the Command Output window

4
NewbieNewbie
4

    Jan 07, 2008#1

    Hi scripters!

    I'm looking for a way to find the Command Output window, because I don't want to select it before running my other script.

    I tried using UltraEdit.document[index].isName("") without success (then again, even if it were successful, I wouldn't know which number is appended to the window name).

    Any ideas on how to do that (if possible)?


    Cheers,

    Cesar

    262
    MasterMaster
    262

      Jan 08, 2008#2

      Inspired by the script function getActiveDocumentIndex() which is used as a support function in quite a few scripts on this board, I have created two functions to retrieve the index of Command Output windows. Feel free to modify them futher to fit your exact purpose.

      Code: Select all

      // Get index of the first tab index of a Command Output window:
      var ix = getFirstCommandOutputWindowIndex();
      if(ix==-1) {
         UltraEdit.outputWindow.write("No Command Output window is open.");
      }
      if(ix!=-1) {
         UltraEdit.outputWindow.write("The first open Command Output window has index #"+
         ix+" and title \""+UltraEdit.document[ix].path+"\"");
      }
      
      // Get index of the most recently opened Command Output Window
      ix = getLatestCommandOutputWindowIndex();
      if(ix==-1) {
         UltraEdit.outputWindow.write("No Command Output window is open.");
      }
      if(ix!=-1) {
         UltraEdit.outputWindow.write("The most recently opened Command Output"+
         " window has index #"+ix+" and title \""+UltraEdit.document[ix].path+"\"");
      }
      
      
      // Find the tab index of the first Command output window document
      // Index -1 = No output window open
      // If index is not -1 it points to the first open Output Window tab.
      // If you have reordered the tabs by drag'n'drop it might not be the
      // first chronologically opened Output Window.
      function getFirstCommandOutputWindowIndex() {
         // If you use a non-English UE you might want to localize this constant:
         var COMMANDOUTPUT = "Command Output";
      
         var tabindex = -1; /* start value */
      
         for (var i = 0; i < UltraEdit.document.length; i++)
         {
            if (UltraEdit.document[i].path.substr(0,COMMANDOUTPUT.length)==COMMANDOUTPUT) {
               tabindex = i;
               break;
            }
         }
         return tabindex;
      }
      
      // Find the tab index of the latest (most recently) opened Command output window document
      // Index -1 = No output window open
      // If index is not -1 it points to the most recently opened Command Output Window
      // by finding the tab with the highest number following "Command Output".
      // Reordering of the tabs by drag'n'drop will be no problem.
      function getLatestCommandOutputWindowIndex() {
         // If you use a non-English UE you might want to localize this constant:
         var COMMANDOUTPUT = "Command Output";
      
         var tabindex = -1; /* start value */
         var maxOutputWin = 0;
         var curOutputWin = 0;
      
         for (var i = 0; i < UltraEdit.document.length; i++)
         {
            if (UltraEdit.document[i].path.substr(0,COMMANDOUTPUT.length)==COMMANDOUTPUT) {
               curOutputWin = parseInt(UltraEdit.document[i].path.substr(COMMANDOUTPUT.length));
               if (curOutputWin>maxOutputWin) {
                  tabindex = i;
                  maxOutputWin = curOutputWin;
               }
            }
         }
         return tabindex;
      }

      4
      NewbieNewbie
      4

        Jan 08, 2008#3

        This is exactly what I needed. Thanks!