Is It Possible To Enter a /command and have 2 panes update?

I have sets of files that I'm constantly reviewing like this:

C:\Unreviewed\Cars\Toyota\

C:\Reviewed\Cars\Toyota\

I'd like to be able to type a command into one of the tabs like /toyota and have:

  • Upper Pane: C:\Unreviewed\Cars\Toyota\
  • Lower Pane: C:\Reviewed\Cars\Toyota\

This way as i review those files, i could move them from unreviewed to reviewed.

Is something like this possible?

NOTE: I have a hundreds of these category pairs so it cannot be a button on the toolbar.

It would not be a problem for me to generate a lengthy script repeating the category pairs over and over again inside of it.

Sounds like a job for a Tabgroup and Navigation Lock

https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Navigation_Lock.htm

A bit more work would be a system of folder aliases and a button or script that opens the destination based on the folder in the source.

I just tired navigation lock. It didn't work. I think it's because I gave an oversimplification of the workflow for clarity.

It's more like this:

C:\Unreviewed\Cars\Toyota
C:\Reviewed\R-Cars\Toyota\

and

C:\Unreviewed\Trucks\Honda
C:\Reviewed\S-Trucks\Honda\

The part I'm trying to simplify is step 1 of a 3 step workflow. The "R-" and S-" are used in step 2 (not described.)

Also, I don't always know where the start folder is, so i want the command to locate it for me. For example, I may not know if Honda is under c:\cars\ or c:\trucks.

So a command would help me go right to it and set me up for review.

The ideal result would be i type a command like:
/Honda

Pane 1: C:\Unreviewed\Trucks\Honda
Pane 2: C:\Reviewed\S-Trucks\Honda\

In that scenerio, i woudn't waste time looking in C:\cars for a honda folder.

Possible?

Try this. You might need to adjust the hotkey.

// https://resource.dopus.com/t/is-it-possible-to-enter-a-command-and-have-2-panes-update/40657

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var dlg = clickData.func.Dlg();
    var fsu = DOpus.FSUtil();
    cmd.deselect = false;

    var st = dlg.GetString('Folder to open:', st);
    if (typeof st != 'string') return;

    var leftStartfolder = 'C:\\Unreviewed';
    var rightStartfolder = 'C:\\Reviewed';

    var folderEnum = fsu.ReadDir(leftStartfolder, 'r');
    while (!folderEnum.complete) {
        var item = folderEnum.Next();
        if (!item.is_dir) continue;
        if (String(item.realpath).indexOf(st) < 0) continue;
        cmd.RunCommand('GO PATH="' + item + '" NEWTAB OPENINLEFT');
    }
    folderEnum.Close();

    var folderEnum = fsu.ReadDir(rightStartfolder, 'r');
    while (!folderEnum.complete) {
        var item = folderEnum.Next();
        if (!item.is_dir) continue;
        if (String(item.realpath).indexOf(st) < 0) continue;
        cmd.RunCommand('GO PATH="' + item + '" NEWTAB OPENINRIGHT');
    }
    folderEnum.Close();
}
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" hotkey="/" textcol="none">
	<label>40657</label>
	<icon1>#newcommand</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>// https://resource.dopus.com/t/is-it-possible-to-enter-a-command-and-have-2-panes-update/40657</instruction>
		<instruction />
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>    var cmd = clickData.func.command;</instruction>
		<instruction>    var dlg = clickData.func.Dlg();</instruction>
		<instruction>    var fsu = DOpus.FSUtil();</instruction>
		<instruction>    cmd.deselect = false;</instruction>
		<instruction />
		<instruction>    var st = dlg.GetString(&apos;Folder to open:&apos;, st);</instruction>
		<instruction>    if (typeof st != &apos;string&apos;) return;</instruction>
		<instruction />
		<instruction>    var leftStartfolder = &apos;C:\\Unreviewed&apos;;</instruction>
		<instruction>    var rightStartfolder = &apos;C:\\Reviewed&apos;;</instruction>
		<instruction />
		<instruction>    var folderEnum = fsu.ReadDir(leftStartfolder, &apos;r&apos;);</instruction>
		<instruction>    while (!folderEnum.complete) {</instruction>
		<instruction>        var item = folderEnum.Next();</instruction>
		<instruction>        if (!item.is_dir) continue;</instruction>
		<instruction>        if (String(item.realpath).indexOf(st) &lt; 0) continue;</instruction>
		<instruction>        cmd.RunCommand(&apos;GO PATH=&quot;&apos; + item + &apos;&quot; NEWTAB OPENINLEFT&apos;);</instruction>
		<instruction>    }</instruction>
		<instruction>    folderEnum.Close();</instruction>
		<instruction />
		<instruction>    var folderEnum = fsu.ReadDir(rightStartfolder, &apos;r&apos;);</instruction>
		<instruction>    while (!folderEnum.complete) {</instruction>
		<instruction>        var item = folderEnum.Next();</instruction>
		<instruction>        if (!item.is_dir) continue;</instruction>
		<instruction>        if (String(item.realpath).indexOf(st) &lt; 0) continue;</instruction>
		<instruction>        cmd.RunCommand(&apos;GO PATH=&quot;&apos; + item + &apos;&quot; NEWTAB OPENINRIGHT&apos;);</instruction>
		<instruction>    }</instruction>
		<instruction>    folderEnum.Close();</instruction>
		<instruction>}</instruction>
	</function>
</button>

I got that to work if i type in "C:\Unreviewed\Cars\Toyota"

The problem is that i may not know where it is and that's a lot of typing, especially since in real life this is on a network share.

I just want to be able to type in "honda" and have it set the panes.

I'm able to programmatically generate a long list that has hundreds of pairs formatted for the script.

IT WOULD BE GREAT IF I COULD:

  1. Hit a button
  2. it prompts me for a keyword
  3. a loooong series of IF statements gets checked and if there is a hit it updates 2 variables for the top and bottom pane location
  4. It sets the panes if the variables are not null at the very end.

Would it be possible to get me going with something like this? Once I see the beginnings of a script that can take the parameter, establish the 2 variables and then at the end update the panes I can probably take it from there.

I tried to take your script and modify it like i outlined in the 1,2,3,4 just above.

I pasted this as a javascript button but it won't work. I think it might be very close to what I'm looking for.
I only have a line for "Honda" in there but i can repeat it when i get everything else to work.

Could you give a bit of guidance? I'm a sql programmer. I don't know Javascript.

function OnClick(clickData) {
	var cmd = clickData.func.command;
    var dlg = clickData.func.Dlg();
    var fsu = DOpus.FSUtil();
    cmd.deselect = false;

// Get the collection name
    var st = dlg.GetString('Collection:', st);
    if (typeof st != 'string') {return};
	
// set the collection name based on a keyword
	if (st = 'honda') { var leftStartfolder = 'C:\Unreviewed\Trucks\Honda';  var rightStartfolder = 'C:\Reviewed\S-Trucks\Honda'; }
	
// If i didn't get a hit abort.
	if (typeof leftStartfolder != 'string') {return};
	if (typeof rightStartfolder != 'string') {return};

// set the top pane	
	 var folderEnum = fsu.ReadDir(leftStartfolder, 'r');
    while (!folderEnum.complete) {
        var item = folderEnum.Next();
        if (!item.is_dir) continue;
        if (String(item.realpath).indexOf(st) < 0) continue;
        cmd.RunCommand('GO PATH="' + item + '" NEWTAB OPENINLEFT');
    }
    folderEnum.Close();

// set the bottom pane	
    var folderEnum = fsu.ReadDir(rightStartfolder, 'r');
    while (!folderEnum.complete) {
        var item = folderEnum.Next();
        if (!item.is_dir) continue;
        if (String(item.realpath).indexOf(st) < 0) continue;
        cmd.RunCommand('GO PATH="' + item + '" NEWTAB OPENINRIGHT');
    }
    folderEnum.Close();

This should work. I'd probably use a spreadsheet to fill the gaps.

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var dlg = clickData.func.Dlg();
    cmd.deselect = false;

    var st = dlg.GetString('Folder to open:', st);
    if (typeof st != 'string') return;

    if (false);
    else if (st == '     ') cmd.RunCommand('GO PATH="                     " DUALPATH="                  "');
    else if (st == '     ') cmd.RunCommand('GO PATH="                     " DUALPATH="                  "');
    else if (st == '     ') cmd.RunCommand('GO PATH="                     " DUALPATH="                  "');
    else if (st == '     ') cmd.RunCommand('GO PATH="                     " DUALPATH="                  "');

}

I think we're super close. But for some reason it's prefixing the windows system directory in front of the variable:

If i type honda it tries to go to C:\Windows\System32\ReviewedS-TrucksHonda
and c:\Windows\System32\UnreviewedTrucksHonda

I pasted the directories into the script to make sure they were exact.
Why would it prefix the windows directory?

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var dlg = clickData.func.Dlg();
    cmd.deselect = false;

    var st = dlg.GetString('Collection Name:', st);
    if (typeof st != 'string') return;

    if (false);
    else if (st == 'honda') cmd.RunCommand('GO PATH="C:\Unreviewed\Trucks\Honda" DUALPATH="C:\Reviewed\S-Trucks\Honda\"');
    else if (st == 'toyota') cmd.RunCommand('GO PATH="C:\Unreviewed\Cars\Toyota" DUALPATH="C:\Reviewed\R-Cars\Toyota"');

}


In JScript, backslashes need to be escaped, e.g.:

cmd.RunCommand('GO PATH="C:\\Unreviewed\\Cars\\Toyota" DUALPATH="C:\\Reviewed\\R-Cars\\Toyota"');
1 Like

Thank you! that would have taken me hours to figure out.

I'm starting to get it working! I can work with the extra slash using a sql database i have that i will use to create the lines.

Thanks so much for your help!!! this is going to save me an insane amount of time.

Hi LXP,
Sometimes these folders may not exist so to prevent an error, it should only change to them if they are there. Your early code had this check but i can't get it to work.

I'm setting the variables with the else if's then just opening the tabs at the bottom if they exist. This was setup combining the different versions you provided. If you could look at the tab openings and give me an idea why the check isn't working that would be great.

Here's what I have:

function OnClick(clickData) {
	var cmd = clickData.func.command;
    var dlg = clickData.func.Dlg();
	var fsu = DOpus.FSUtil();
    cmd.deselect = false;

// Fetch collection name
    var st = dlg.GetString('Collection Name:', st);
    if (typeof st != 'string') return;

// set the top/bottom pane variables based on a keyword entered
	if (false);
	else if (st == 'honda') { var leftStartfolder = 'C:\\Unreviewed\\Trucks\\Honda';  var rightStartfolder = 'C:\\Reviewed\\S-Trucks\\Honda'; }
	else if (st == 'toyota') { var leftStartfolder = 'C:\\Unreviewed\\Cars\\Toyota';  var rightStartfolder = 'C:\\Reviewed\\R-Cars\\Toyota'; }

// set the top pane	if the directory exists
	 var folderEnum = fsu.ReadDir(leftStartfolder, 'r');
    while (!folderEnum.complete) {
        var item = folderEnum.Next();
        if (!item.is_dir) continue;
        if (String(item.realpath).indexOf(st) < 0) continue;
        cmd.RunCommand('GO PATH="' + item + '" NEWTAB OPENINLEFT');
    }
    folderEnum.Close();

	// set the bottom pane if the directory exists.
    var folderEnum = fsu.ReadDir(rightStartfolder, 'r');
    while (!folderEnum.complete) {
        var item = folderEnum.Next();
        if (!item.is_dir) continue;
        if (String(item.realpath).indexOf(st) < 0) continue;
        cmd.RunCommand('GO PATH="' + item + '" NEWTAB OPENINRIGHT');
    }
    folderEnum.Close();
		
}

There are two approaches for the script. Either search for the folder in the directory structure or look up the folder from a table. A search can be slower and might return unwanted results. A look-up table is very precise, but needs a bit of maintenance, as you just found out.

You need to decide which solution works best for you.

Sorry my bad, I'm not being clear enough. This is a pretty extensive workflow I'm trying to introduce this to.

Sometimes, these folders are not there but, they belong there. The script will absolutely know where they belong based on a database i have. However, If they haven't been created (yet) I need to check for that to prevent an error.

So that's why I'm looking to simply check the existence of the directory before attempting to open it. Ideally, I'd like to create it if it doesn't exist. At the least I need to check it's existence and prevent it from getting an error.

How can I identify the existence of a folder before attempting to open/create it in a pane?

DOpus.FSUtil.Exists

Examples

Just create it without checking first. Nothing will happen if it already exists.

1 Like

I got it! Now it creates a directory if it doesn't exist too!

I have over 800 else ifs in my final version and it's super quick!

This is going to do so much "looking stuff up" for me.

Thanks so much lxp & Leo! Directory Opus rules!

Here's my final version if anyone ever needs it. All someone needs to do is populate the else if's with rows of their choosing and pairs will appear when they match what's typed in the dialog:

function OnClick(clickData) {
	var cmd = clickData.func.command;
    var dlg = clickData.func.Dlg();
	var fsu = DOpus.FSUtil();
    cmd.deselect = false;
	DOpus.ClearOutput();

// Fetch collection name
    var st = dlg.GetString('Collection Name:', st);
    if (typeof st != 'string') return;

// set the top/bottom pane variables based on a keyword entered
	if (false);
	else if (st == 'honda') { var leftStartfolder = 'C:\\Unreviewed\\Trucks\\Honda';  var rightStartfolder = 'C:\\Reviewed\\S-Trucks\\Honda'; }
	else if (st == 'toyota') { var leftStartfolder = 'C:\\Unreviewed\\Cars\\Toyota';  var rightStartfolder = 'C:\\Reviewed\\R-Cars\\Toyota'; }

DOpus.Output('collection name = '+ st);
DOpus.Output('leftStartfolder = '+ leftStartfolder);
DOpus.Output('rightStartfolder = '+ rightStartfolder);

if (typeof leftStartfolder == 'undefined') { DOpus.Output('Aborting: Top Doesnt Exist');  return;}
if (typeof rightStartfolder == 'undefined') { DOpus.Output('Aborting: bottom Doesnt Exist');  return;}

// Find out if these directories exists
var leftexists = fsu.Exists(leftStartfolder);
if (leftexists == false) DOpus.Output('Top Doesnt Exist');
if (leftexists == true) DOpus.Output('Top Exists');

var rightexists = fsu.Exists(rightStartfolder);
if (rightexists == false) DOpus.Output('Bottom Doesnt Exist');
if (rightexists == true) DOpus.Output('Bottom Exists');

// set the top pane	
if (leftexists == false) {
	cmd.SetSourceTab(cmd.sourcetab);
	cmd.RunCommand('CreateFolder NAME="' + leftStartfolder + '" READAUTO');
	leftexists = fsu.Exists(leftStartfolder);
	}
if (leftexists == true)  cmd.RunCommand('GO PATH="' + leftStartfolder + '" NEWTAB OPENINLEFT');

// set the Bottom pane	if the directory exists
if (rightexists == false) {
	cmd.SetSourceTab(cmd.desttab);
	cmd.RunCommand('CreateFolder NAME="' + rightStartfolder + '" READAUTO');
	rightexists = fsu.Exists(rightStartfolder);
	}
if (rightexists == true)  cmd.RunCommand('GO PATH="' + rightStartfolder + '" NEWTAB OPENINRIGHT');

}

2 Likes

Serious stuff! Happy finding :+1:

1 Like