AutoOpenPairedFolder (Add-in)

This add-in will open a paired folder in the destination if it detects a valid folder while navigating a lister.

The implementation is rather basic, there are more options available. See the docs for details.

How to set up and use

Save EventAutoOpenPairedFolder.js.txt to   

%appdata%\GPSoftware\Directory Opus\Script AddIns

Things you might enjoy reading

Docs: FSUtil GetFolderPair
Docs: PairedFolder
Forum: Regex-based Paired Folders - Tutorials
FAQ: How to use buttons and scripts from this forum

The script's inner workings

function OnInit(initData) {
    initData.name = 'AutoOpenPairedFolder';
    initData.version = '2024-06-28';
    initData.url = 'https://resource.dopus.com/t/autoopenpairedfolder-add-in/46353';
    initData.desc = 'Open paired folder in destination';
    initData.default_enable = true;
    initData.min_version = '13.0';
}

function OnAfterFolderChange(afterFolderChangeData) {
    if (!afterFolderChangeData.result) return;

    var tab = afterFolderChangeData.tab;
    if (!tab) return;

    var fsu = DOpus.FSUtil();
    var pairedFolder = fsu.GetFolderPair(tab.path);
    if (!pairedFolder.valid) return;

    var cmd = DOpus.Create().Command();
    cmd.SetSourceTab(tab);

    cmd.RunCommand('Go' +
        ' PATH="' + pairedFolder.path + '"' +
        ' NEWTAB=findexisting' +
        ' OPENINDUAL' +
        ' NOSCRIPT');
}
7 Likes

Damn, that worked a treat! Thank you!

Thanks very much. I had paired my Music Archive folder with my MP3 Player folder, much of which has the same folder structure. After playing a little with your script and turning it off and on a few times I have decided I like it just as it is with the newtab=findexisting. I also set Prefs to include all subfolders.

In Opus 12 I used Leo's Go Parallel script for these folders and found it to be a very useful navigation button with the Toggle and Select command switches.

Using these two scripts together creates all kinds of new scenarios, but what tabs are what can get a little confusing. However, I think in real use this dual scripting will be more useful than a hindrance or a cause of confusion.

Might make sense to add NOSCRIPT to the Go command it runs, to make sure the script doesn't react to folder changes it did itself.

(Definitely needed if NEWTAB=findexisting is removed, but probably a good idea in general.)

1 Like

Update 2024-06-28

  • Added NOSCRIPT
4 Likes

Now even if I remove the line

' NEWTAB=findexisting' +

from the code to make it open the Paired Folder in the same Tab of the destination folder, it works fine. :smiley: Thanks @lxp . Thanks @Leo .

1 Like

Fantastic little script!

Personally, I think Dopus should make this an option for paired folders. Some of the options that are already on the Paired Folders screen kind of alludes to that functionality even....

But still, this little script does the trick in the meantime!

Thanks!

@drventure

See the code in item 5 of Paired Folders - Nav Lock issues - #5 by jimerb

@showif:=return Len(Resolve(source, "p")) > 0
function OnClick(clickData)
{
	var cmd = clickData.func.command;
	// See https://resource.dopus.com/t/paired-folders-are-they-already-functional/46101/5
	cmd.runcommand("Go OPENINDUAL NEWTAB=findexisting PATH {sourcepath|pair}");
}

A button will appear only when you open a folder that is part of a paired folder. You can then decide to open the pair or not. Click on the button and it will open the other half of the pair in the other side of a dual lister. Kudos to @aussieboykie

What exactly is a valid folder? I have the script installed, navigate to a folder of which i know there exists a paired folder, but it won't be opened in the destination. There's no config cog either, to change any details.

Will it open if you run?

Go PATH={sourcepath|pair} OPENINDUAL

No, nothing happens, whether being inside the paired folder, nor having it selected from the outside. The script is installed of course.

Maybe the folder pair is disabled?

No, both folders are present in my standard tab set. So if i click either of them, the paired folder tab is activated. I'm not quite sure how your script is supposed to work, like, if it would fetch the paired folder, even if it's not present somewehere in the destination as an existing tab (i guess this is how the script is supposed to work).

The script works when you change folders, not when you activate a tab that's already in a folder.

(You could make it do both, but that's what it does currently.)

What do you mean by change folders? Like i wrote, if i enter a folder that is part of a pair, nothing happens. So change doesn't mean to go into that folder? :thinking:

When you are already in a folder tab, and then change from one folder to another in that tab.

In any folder tab? Or does it have to be part of a paired folder yet? So, i'm in a paired folder, go into a subfolder here, and on the other side nothing changes. Maybe you can give me some instruction, what exactly to do?

The script's effect will be most visible when you start with a lister in single-display mode.

No, i see no effect here. I don't even have that "paired" symbol on the tabs here, since the may belong to that dual display mode, and even the "link tabs" symbol is missing from the menu. I also don't see, what would happen in a single display mode with that script. So i'd enter tab A, and it will open the linked tab B instead?

By the way, i very often have read about scripts here, that sounded interesting, but in maybe 90% of the cases i had no idea, what exactly they would do, despites having a (too short) description included at the top.