GoExisting - open path, focusing existing tab if found on either side

Jon very kindly made this script on this thread. It seems that it'll be useful to more people so I thought I'd repost it here with a more general name.

The script is also explained on the DearOpus scripts page.

The usage is GoExisting path
This will open the specified path. If it already exists in an open tab, on either side of a dual lister, that tab will be recycled and focused. It's similar to the findexisting argument, but it searches both sides of a dual lister.

Please anyone feel free to publish other versions, I just wanted to make a thread for the script.

Update:
ScriptWizard-enabled.

Download:
GoExisting.js.txt (5.75 KB)

1 Like

For a long time now I have used a series of buttons tied to a modified GO script that defaults to NEWTAB=findexisting but my version did not check both sides of a DUAL. This is a very nice addition @jon and @playful and @jon's ++index[e.item().right ? 1 : 0]; technique taught me something I had not seen in action before.

I like to use ctrl and shift qualifiers to open in dual or open in NEW. Here is a version that does that.

// GoExisting
// Original code written by @jon
// Tweaked by @playful and posted as version 1
// USEQUALKEYS support added by @aussieboykie
// 
// This is a script for Directory Opus.
// See http://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information.
// 
// Also see https://resource.dopus.com/t/findexisting-anyside/20095/6
//
// Called by Directory Opus to initialize the script
function OnInit(initData)
{
   initData.name = "GoExisting";
   initData.desc = "";
   initData.copyright = "";
   initData.version = "1.1";
   initData.default_enable = false;

   var cmd = initData.AddCommand();
   cmd.name = "GoExisting";
   cmd.method = "OnGoExisting";
   cmd.desc = "Equivalent of Go NEWTAB=findexistingdual";
   cmd.label = "GoExisting";
   cmd.template = "PATH";
}

// Implement the GoExisting command
function OnGoExisting(scriptCmdData)
{
   var cmdPfx = 'Go "' + scriptCmdData.func.args.path + '"';
   var cmdSfx = (scriptCmdData.func.qualifiers == "none") ? "":" USEQUALKEYS";
   var cmdString = cmdPfx + cmdSfx;
   if (scriptCmdData.func.sourcetab.lister.dual == 0) {
      cmdString = cmdString + " NEWTAB=findexisting";
      scriptCmdData.func.command.RunCommand(cmdString);
   }
   else {
      if (!DoGoExisting(scriptCmdData, scriptCmdData.func.sourcetab.lister.tabs)) {
         cmdString = cmdString + " NEWTAB";
         scriptCmdData.func.command.RunCommand(cmdString);
      }
   }
}

function DoGoExisting(scriptCmdData, tabs)
{
   var FSUtil = DOpus.FSUtil();
   var e = new Enumerator(tabs);
   var index =  new Array(0, 0);
   e.moveFirst();
   while (!e.atEnd())
   {
      if (FSUtil.ComparePath(e.item().path, scriptCmdData.func.args.path))
      {
         if (scriptCmdData.func.sourcetab.right != e.item().right)
            scriptCmdData.func.command.AddLine('Set FOCUS=toggle');
         scriptCmdData.func.command.AddLine('Go TABSELECT ' + index[e.item().right ? 1 : 0]);
         scriptCmdData.func.command.Run();
         return true;
      }
      ++index[e.item().right ? 1 : 0];
      e.moveNext();
   }
   return false;
}

Regards, AB

Hey aussieboykie,
Thank you, it's great to see that thing evolve.

For the record I didn't tweak anything, only changed the name. :slight_smile:

I liked the original name myself :slight_smile:

Yeah I suppose descriptive names are overrated. Remember when you could get away with calling things v1, v2, v3, or calling the princess "kong" and the gorilla "cinderalla" Those where the days. :wink:

@jon
I see why! Leaving names as they are won't yield problems, like when switching lang.. just kidding! o))

@aussie
Why is it, you only add the USEQUALKEYS switch to the GO command, when there are qualifiers held down?
Will there be any harm if USEQUALKEYS is always present and no qualifier held down? I'd say no, but not sure.

@tbone

I'm sure you are right. A simple case of over engineering!

Regards, AB

"Over engineering", I think I like that expression. o) Ok, thank you for clarifying. I am not familiar with that switch, never used it myself, but wanted to make sure to not miss a thing. I fixed the non-mirroring issue within the existing versions, will upload anytime soon. A nice weekened for all! o)

I like this but recently discovered something that doesn't work as I expected.

This code works (Go NEWTAB=findexisting command):

Go {dlgchooseS|Select Whatever:|Desktop="c:\users\%username%\desktop"+Documents="c:\users\%username%\documents" NEWTAB=findexisting
set QUICKFILTER ~.lnk

This doesn't work (GoExisting command):

GoExisting {dlgchooseS|Select Whatever:|Desktop="c:\users\%username%\desktop"+Documents="c:\users\%username%\documents"
set QUICKFILTER ~.lnk

Am I doing something wrong?

The internal Go NEWTAB command will automatically funnel commands that come after it into the new tab, but that doesn't happen for commands added by scripts. You're probably setting the quickfilter on the old tab and not the new one as a result.

As a quick kludge, try dopusrt /acmd set QUICKFILTER ~.lnk in place of the second line. That may get the command to run in the new tab without having to modify the script.

1 Like

That works, thanks Leo.

Hi everyone! is this script still working? i've had it for ages and I'm now noticing it no longer seems to work...

Works fine here.

so if i have a locked tab showing dloads, open a new tab, type an alias for my dloads folder, should it go to the locked tab ? it doesn't. ok maybe my configuration is in bad shape....

I don't know. You didn't mention any of those details before so I didn't test them.

Why not start by checking it works with a simple situation? It could be something trivial, like the add-in is disabled entirely. Or it could be something that depends on particular details of what you're doing, in which case working out what those are is the next step if you want to solve it.

I actually hadn't realized it is NOT supposed to work that way. I clicked on a button that takes me to dloads and it worked.
Thans a lot Leo !!

How do I make this just work for every folder i open?

Open in which way(s)?

Please link your account.