Finding the Command Output window

Help with writing and running scripts

Finding the Command Output window

Postby Cesar » Mon Jan 07, 2008 4:19 pm

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
User avatar
Cesar
Newbie
 
Posts: 4
Joined: Mon Dec 24, 2007 12:00 am

Re: Finding the Command Output window

Postby jorrasdk » Mon Jan 07, 2008 9:49 pm

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;
}
User avatar
jorrasdk
Master
Master
 
Posts: 275
Joined: Mon Mar 19, 2007 11:00 pm
Location: Denmark

Re: Finding the Command Output window

Postby Cesar » Tue Jan 08, 2008 1:48 pm

This is exactly what I needed. Thanks!
User avatar
Cesar
Newbie
 
Posts: 4
Joined: Mon Dec 24, 2007 12:00 am


Return to Scripts

cron