Does NEWTAB=findexisting not work from dopusrt?

I'm playing in AHK, using dopusrt to open paths extracted from programs.

Run, %dopusrt% /cmd Go "%filename%"  NEWTAB=findexisting ; TOFRONT
Run, %dopusrt% /cmd Go "%filename%"  NEWTAB=deflister,findexisting ; TOFRONT
Run, %dopusrt% /cmd Go "%filename%"  NEWTAB=findexisting,tofront
Run, %dopusrt% /acmd Go "%filename%"  NEWTAB=findexisting OPENINLEFT TOFORNT

so everyone of those lines works... Except for the "findexisting". which works from bottons inside of dopus but not when launched through %dopusrt%...

can dopusrt not use findexisitng?
is there a bug here?
am I missing something?

thanks
x

It should work, but is probably not being run on the window you expect.

More detail on what happens is needed to say anything more definitive.

do you have AHK installed on your machine??

try this script if you do

the hotkey is 1
esc will kill it.

paste a file path into the box, it will open in new tab and select the file. this part works. (or use the provided notepad.exe path I put in there)

run the hotkey a few times in row, on the same file, see if it opens a new tab every time or reuses an existing one.

for me "findexisting" is ignored and a new tab is opened every time.

the code below is dopusrt equivalent of Run, explorer.exe /select, "%filename%"

; dopusrt NEWTAB=findexisting test.ahk
#SingleInstance, Force
#Persistent

1::
InputBox, filepath, dopusrt findexisting tab text, Paste a File Path. Run this hotkey a few times in a row.,,,,,,,,C:\Windows\System32\notepad.exe
if !FileExist(filepath)
	{
		MsgBox, 262144, , File Not Found`, try again., 4
		return
	}
Run, "C:\Program Files\GPSoftware\Directory Opus\dopusrt.exe" /cmd Go "%filepath%"  NEWTAB=findexisting TOFRONT OPENINLEFT
return

~esc::
exitapp
return

Try adding EXISTINGLISTER to the Go command, so it searches all open tabs/windows, not just the one the command is sent to.

no luck with existinglister

in this example i can seletle a path in any text doc, and sed it it do opus.
%A_ScriptDir%\x ahks x.ahk
ahk expand the script dir its

C:\Users\CLOUDEN\Documents\AutoHotkey\x ahks x.ahk

this function cleanuppathstring() splits the path if a file is at the end it splits at the last dir and selected the file.

if only a dir is selected it will find an existing tab.
if the file is selected it will open a new tabs, ignored the other 7 i just opened.

pgdn:: ; %A_ScriptDir%\x ahks x.ahk
OpenDIRselection:
Global ClipSaved, filename, dir, ext, filestem, drive, lastfolder
iflive()
sleep 75
cleanuppathstring()
sleep 75

if (FileExist(Clipboard))  ; Check if it's a file or directory ; //If path exists
{
	FileGetAttrib, Attributes, %Clipboard%
	if (InStr(Attributes, "D"))  ; If it's a directory
	{
		try Run, %Clipboard%  ; Open folder
		sleep 20
		restoreclipboard()
		Return
	}
	else ; If it's a file
	{
		try Run, %dopusrt% /cmd Go "%Clipboard%" NEWTAB TOFRONT EXISTINGLISTER 
		catch
		Run explorer.exe /select`,"%clipboard%"
		sleep 20
		restoreclipboard()
		Return
	}
}
else if InStr(Clipboard, "%")  ; If it contains environment variables
{
	try Run, %dopusrt% /cmd Go "%Clipboard%" NEWTAB TOFRONT EXISTINGLISTER 
	catch
	try Run explorer.exe /select`,"%clipboard%"
	sleep 20
	restoreclipboard()
	Return
}
else ; If the path doesn't exist, show the "Directory Not Found" message
{
	ToolTip, Directory Not Found
	Sleep, 1500
	ToolTip
	sleep 20
	restoreclipboard()
	sleep 100
}
return

is there away to use go on the dir and select the file?

 SplitPath, Clipboard, filename, dir, ext, filestem, drive ;; from the cleanuppathstring()

;; it could be..

try Run, %dopusrt% /cmd Go "%Dir%\%filename%" NEWTAB TOFRONT EXISTINGLISTER 

that works only for the dir, ignoreing the file

this has been driving me crazy for a year. i have many key and menu items through ahk that get filepaths coming from various program\places\reads\clipboard etc. and opens them in dopus, with the active file selected!

i love it except as stated above, it opens a newtab every time. in this codeblock I'm testing /cmd layout by moving the args around, escaping ahk "`," etc and i have 15+ identical tabs all with the same file selected.

Testing_DopusRT_GO_NewTab_findexisting:
sel := "X:\AHK\xINC" ;; if sel is a folder path it will findexisting tabs activating them

sel := "X:\AHK\xINC\x [set].ahk" ;; IF sel is a full file path it will open a new tab every time

; in the process to trying to text /cmd options in different layouts while sending a c:\filepath.ext have about 15 tabs open to the same folder, each with the samefile selected.

Run, %dopusrt% /acmd Go "%sel%" NEWTAB=tofront,findexisting ;; crates new tab when one exists already
Run, %dopusrt% /acmd Go "%sel%" NEWTAB=findexisting,tofront ;; ALSO.. crates new tab when one exists already

Run, %dopusrt% /acmd Go "%sel%" NEWTAB=findexisting TOFRONT ;; ALSO.. crates new tab when one exists already (have 4 open now)
Run, %dopusrt% /cmd Go "%sel%" NEWTAB=findexisting TOFRONT ;; also and now 5 tabs 

Run, %dopusrt% /cmd Go "%sel%" NEWTAB=findinactive TOFRONT ;; also have 6 tabs now

Run, %dopusrt% /acmd Go "%sel%" NEWTAB=findinactive TOFRONT ;; also now 7 tabs
Run, %dopusrt% /acmd Go "%sel%" findinactive TOFRONT ;; no new tabs, dopus does nothing
Run, %dopusrt% /cmd Go "%sel%" findinactive TOFRONT ;; no new tabs, dopus does nothing
Run, %dopusrt% /acmd Go "%sel%" findinactive TOFRONT ;; nothing
;-------------------------
/acmd Go "%1" NEWTAB=deflister,findexisting TOFRONT ;; copied directly from listary.exe, this opens an exiting tab out of the 7 with out opeening a new one
run, %dopusrt% /acmd Go "%sel%" NEWTAB=deflister,findexisting TOFRONT ;; run the same ▲▲▲ from ahk and it opens a another newtab
;-------------------------
run, %dopusrt% /acmd Go "%sel%" NEWTAB=findexisting EXISTINGLISTER TOFRONT ;; escaped comma`, still opens a new tab, about 9 of them now.
run, %dopusrt% /acmd Go "%sel%" NEWTAB=findexisting TOFRONT ;; escaped comma`, still opens a new tab, about 9 of them now.
run, %dopusrt% /acmd "%sel%" NEWTAB=deflister,findexisting TOFRONT ; // removing GO runs the file insteand
run, %dopusrt% /acmd Go "%sel%" NEWTAB=deflister,findexisting TOFRONT

return

so =findexisting is ignored if Go points to File and Not a folder?

when send a %dir% rather than a %filepath% it stops creating new tab, but than lose selecting the file that being sent via Go "%filepath%"

Is there a way to have dopurt split the filepath down to the last %FileDir% and select the %filename%?? such as explorer.exe does with Run, explorer.exe /select, "%A_File%"

is there another command I'm unaware of the open the a dir and then select a particular file?

do i need to split that path my self to run two cmds, eg, -Go %y% then -Select %x%?

if i use Run, %dopusrt% /acmd Go "%sel%" i won't get a dozen tabs but than i losing which ever tab is active as tis change to the selected path.

well i almost anwered my question.
findexisting with a dir path works
findexising with a file path does not

I'm discovering Select in cmds which i can pass a Var to

so i tried breaking the the cmd into two separate lines, open the tab to the dir, then select the file

Testing_DopusRT_GO_NewTab_findexisting_Sent_as_two_CMDs:

sel := "X:\AHK\xINC\x [set].ahk" ;; IF sel is a full file path it will open a new tab every time

splitpath, sel, name, dir  ;// have ahk split the path to seprate the dir and filename ;// tip(dir A_space name)


;// Run, %dopusrt% /cmd Go "%dir%" NEWTAB=findexisting TOFRONT Select "%name%" EXACT ;// this as one line won't run

;// as two separate runs.
Run, %dopusrt% /cmd Go "%dir%" NEWTAB=findexisting TOFRONT

sleep 200 ;// without a sleep\wait the file might not get selected as the next line\cmd runs before the 1st cmd above isnt finished opening the dir\tab

run, %dopusrt% /cmd Select "%name%" EXACT

;// running at two cmds seems to work, the 2nd command cause the lister window to flash as its  received.
return

is there way to combine these into single cmd line??

I see two ways:

  • Creating a dcf file on the fly to get both actions in it (see DOpusRT Reference [Directory Opus Manual])
  • Create a new custom command (something like GoAndSelect) with two parameters (PATH and FILE?) and then invoke that new command from your ahk script through dopusrt. You'd give it the path to open and the file to select.

If I had to do it, I'd go with the second option.

option #2 easy to start... I've have a few dozens places in my script where paths are sent to DO, will have to edit\add each of this passed vars as "Global" in the function. that a picky ahk shortfall

OpenToFileInDopus(path)
{
    global dopusrt
    If !FileExist(path)
    {
        Tip(path " was not found. Opening in Dopus canceled.", 3500)
        Return
    }
    
    splitpath, path, name, dir
    Run, %dopusrt% /cmd Go "%dir%" NEWTAB=findexisting TOFRONT
    sleep 200
    Run, %dopusrt% /cmd Select "%name%" EXACT
}

this also needs a fall back check, it will error out if a dir is sent without a file

semi - relasted to QuickAccessPopup, which i love.

he has toggles for newtab vs active tab. the newtab switched on open new tabs in new listers. ha. QAP code is over my head thou so I'm not sure how to make a suggest here or to jean on that one. id rather have duplicate tabs than 5 duplicate listers with one odd tab out on each.

Not sure I get you (I'm not familiar with ahk). What I meant was a custom Opus command.
So instead of doing:

Run, %dopusrt% /cmd Go "%dir%" NEWTAB=findexisting TOFRONT

sleep 200 ;// without a sleep\wait the file might not get selected as the next line\cmd runs before the 1st cmd above isnt finished opening the dir\tab

run, %dopusrt% /cmd Select "%name%" EXACT

You'd just do:

Run, %dopusrt% /cmd MyCustomGoAndSelect DIR="%dir%" NAME="%name%"

And the commands GO NEWTAB and SELECT would be in the Opus custom command.
You'd have to act there with only GO if no file is sent...

EDIT: The script below does that.
GoAndSelect.opusscriptinstall (1.1 KB)

Note that, selection of the new file does not replace any existing selected file. For that you'd need to change the Select command in the script (I don't remember the switch).

EDIT2: Script code:

// Called by Directory Opus to initialize the script
function OnInit(initData)
{
	initData.name = "GoAndSelect";
	initData.version = "1.0";
	initData.copyright = "(c) 2025 Stephane";
//	initData.url = "https://resource.dopus.com/c/buttons-scripts/16";
	initData.desc = "";
	initData.default_enable = true;
	initData.min_version = "13.0";


}

// Called to add commands to Opus
function OnAddCommands(addCmdData)
{
	var cmd = addCmdData.AddCommand();
	cmd.name = "GoAndSelect";
	cmd.method = "OnGoAndSelect";
	cmd.desc = "";
	cmd.label = "GoAndSelect";
	cmd.template = "DIR/O,NAME/O";
	cmd.hide = false;
	cmd.icon = "script";
}

function OnGoAndSelect(scriptCmdData) {
	var cdf = scriptCmdData.func;

	// Check for DIR parameter
	if (!cdf.args.got_arg.dir) {
		dout("No directory to open provided. Exiting.", true);
		return;
	}
	var dir = cdf.args.dir;

	var name = "";
	if (cdf.args.got_arg.name) {
		name = cdf.args.name;
	}

	var cmd = DOpus.Create.Command();
	cmd.AddLine('GO "' + dir + '" NEWTAB=findexisting TOFRONT');
	if (name != "")
		cmd.AddLine('Select "' + name + '" EXACT');

	cmd.Run();

}


function dout(msg, error, time) {
	if (error == undefined) error = false;
	if (time == undefined) time = true;
	DOpus.Output(msg, error, time);
}

do u mean create this inside of dopus? via Customize > User Commands and then call it through ahk?? hmmm..

that's an idea. in my /dopusdata\user data folder i keep spical buttons so i can call from ahk with, `run, %dopursrt% /cmd "%doupsUD%\my saved button.dcf"

how does dopus splitpaths internally??

ahk has SplitPath . eg.
SplitPath, INVarPath, [ OUTFileName, OUTDir, OUTExt, OUTFileNameStem, OUTDrive ] ; this out vars can be sent to fuctions or subs independent of the INVarPath

this function does this in one line.. when called, it splits the input and run the cmds on on their own using the pieces

selected := "c:\a full file\path\coming from some other var.txt"
OpenToFileInDopus(selected)
or 
OpenToFileInDopus(A_file)
or
OpenToFileInDopus(clipboard)
; now this fuction will open any var i pass to it 
; or in quotes for a static path
OpenToFileInDopus("C:\Users\USERNAME\AppData\Roaming\GPSoftware\Directory Opus\Buttons\Menu.dop") ;; this will open /Buttons and select Menu.dop

just saw this button, i need to learn .js :slight_smile:

ill try playing with this.

Yes. I'd rather do it with a script add-in rather than a custom command, but it'd get you the same result.
See the edit in my previous post, I've made the command.
Just open the Script Manager dialog (by default it should be in Settings/Script). Then drop the .dopusscriptinstall file provided.
You now have a new command in Opus which is called GoAndSelect and it takes one or two parameters which are DIR and (optionaly) NAME.

You can now call that function everywhere you could call any built-in function: a button, dopusrt ...

So you can go with:

Run, %dopusrt% /cmd GoAndSelect DIR="%dir%" NAME="%name%"

Why would you want to split this path?

Or do you mean you'd want that new command to be smarter and try and see if it's dealing with a folder or a file and dealing with it accordingly.

This is possible, but a little more complicated (not that much).

this is smoother than custom func thank you.

on ahk i still need to spilit the path

lets say the file is missing just sending a dir cause the parent to be opened with the dir selected, rather than opening into the last dir.

OpenToFileInDopus(path)
{
splitpath, path, name,dir
 if InStr(FileExist(path), "D")  ; the the path is a folder
     Run, %dopusrt% /cmd Go "%dir%" ;; so i don't end up in the parent dir? with the 
else ; it's a file
     Run, %dopusrt% /cmd GoAndSelect DIR="%dir%" NAME="%name%"
}

this is good idea thou. ill try makiing user cmd or a .dcf in dopus to trigger

We'll make that work in the next beta.

2 Likes

Here is an update:
GoAndSelect.opusscriptinstall (1.4 KB)

It can now take another parameter FULLPATH, which is exclusive to the other two.
When you provide a fullpath which is:

  • A path to an existing file: it opens the tab and selects the file
  • A parh to an existing folder: it opens the tab and does no selection
  • A path to a non existing file or folder: it tries to open the parent if it exists, does nothing otherwise

Code:

// GoAndSelect
// (c) 2025 Stephane

// This is a script for Directory Opus.
// See https://www.gpsoft.com.au/endpoints/redirect.php?page=scripts for development information.



// Called by Directory Opus to initialize the script
function OnInit(initData)
{
	initData.name = "GoAndSelect";
	initData.version = "1.1";
	initData.copyright = "(c) 2025 Stephane";
//	initData.url = "https://resource.dopus.com/c/buttons-scripts/16";
	initData.desc = "";
	initData.default_enable = true;
	initData.min_version = "13.0";


}

// Called to add commands to Opus
function OnAddCommands(addCmdData)
{
	var cmd = addCmdData.AddCommand();
	cmd.name = "GoAndSelect";
	cmd.method = "OnGoAndSelect";
	cmd.desc = "";
	cmd.label = "GoAndSelect";
	cmd.template = "DIR/O,NAME/O,FULLPATH/O";
	cmd.hide = false;
	cmd.icon = "script";
}

function OnGoAndSelect(scriptCmdData) {
	var cdf = scriptCmdData.func;
	var fsu = DOpus.FSUtil;

	var dir = "";
	var name = "";
	
	if (cdf.args.got_arg.fullpath) {
		if (fsu.Exists(cdf.args.fullpath)) {
			var fp = fsu.GetItem(cdf.args.fullpath);
			if (fp.is_dir) {
				dir = String(fp);
			}
			else {
				dir = String(fp.path);
				name = String(fp.name);
			}
		}
		else {
			var sp = SplitPath(cdf.args.fullpath);
			//dout("p=" + sp.p + " || f=" + sp.f);
			if (!fsu.Exists(sp.p)) {
				dout("Provided input can not be processed. Exiting.", true);
				return;
			}
			else {
				dir = sp.p;
				name = "";
			}
		}
	}
	else {
		// Check for DIR parameter
		if (!cdf.args.got_arg.dir) {
			dout("No directory to open provided. Exiting.", true);
			return;
		}
		dir = cdf.args.dir;

		if (cdf.args.got_arg.name) {
			name = cdf.args.name;
		}
	}

	var cmd = DOpus.Create.Command();
	cmd.AddLine('GO "' + dir + '" NEWTAB=findexisting TOFRONT');
	if (name != "")
		cmd.AddLine('Select "' + name + '" EXACT');

	cmd.Run();

}

function SplitPath(s) {
	s = s + "";
	s = s.replace(/\\/g, "/");
	var p = "";
	var f  = "";
	while (s.length > 0 && s.slice(-1) == "/")
		s = s.slice(0,-1);

	var slashPos = s.lastIndexOf("/");
	if (slashPos != -1)	{
		if (s.substring(slashPos-1,slashPos) != ":") {
			f = s.slice(slashPos+1);
			p = s.substring(0, slashPos);
		}
		else {
			f = "";
			p = s;
		}
	}
	else {
		f = "";
		p = s;
	}

	return { "p": p, "f": f };
}


function dout(msg, error, time) {
	if (error == undefined) error = false;
	if (time == undefined) time = true;
	DOpus.Output(msg, error, time);
}

EDIT: Slight change in the script to handle first level folders (just below drive root). Asking fullpath on something like C:\\NonExistingFolderAtRootLevel will do nothing (will not open C:\)

2 Likes