Script: Check Left Lister is Source before Synchronization

First off, I'm a complete novice with DOpus script — i.e., this is my first attempt at writing one.

Second, I know that DOpus has a "Synchronize left-to-right" option, but that's not quite what I'm after.

I would like a script that warns if the Left Lister is not the active Lister before each Synch operation is executed. There are many occasions where I move from left to right, clicking checkboxes, hiding items that won't be synched, etc., and I want to ensure that during that process, I don't inadvertently synch in the wrong direction (unless I explicitly choose to do so).

My first issue is that I can't seem to get the version, description, etc., to show up in the Script Management dialog. I choose File > Install, but the Version doesn't appear in the Install Script dialog; and if I choose OK to install the script, the script doesn't appear in the Script Management dialog, even though I get a "Script installed successfully" message.

Second, could someone please confirm that the script functionality looks correct?

So with all that said, here's my first kick at the script (which I haven't tried running yet):

function OnInit(initData) {
    initData.name           = "Check Sync Left"
    initData.version        = "0.1.0"
    initData.author         = "Trevor Morris"
    initData.desc           = "Checks if the Left Lister is the active Lister before starting a synchronization."
    initData.default_enable = true;
}

function OnBeforeCommand(scriptCmdData) {

    // ensure the command is Sync
    if (scriptCmdData.func.command.name.toLowerCase() !== 'sync') return;
    
    // get the Listers
    var leftLister = scriptCmdData.func.sourcetab.lister;
    var activeLister = DOpus.listers.lastactive;

    // compare the active Lister with the Left Lister
    if (leftLister != activeLister) {

        // confirmation dialog
        var dlg = DOpus.Dlg;
        dlg.window = activeLister;
        dlg.message = "The Left Lister is not the active Lister.\n\nDo you want to proceed with synchronization?";
        dlg.buttons = "Yes|No";
        dlg.icon = "warning";
        var result = dlg.Show();

        // abort Sync if "No" is selected
        if (result == 2) {
            scriptCmdData.func.command.RunCommand("@abort");
        }
    }
}

Thanks! :grin:

There's no OnBeforeCommand event, so I don't think that will work.

AFAIK there isn't a way to run a check before the Synchronize panel does something.

That might also be why the script doesn't stay in the list; it's not implementing anything events or commands etc. which Opus would use, only OnInit.

What's wrong with the built-in Sync Left-to-Right option? This is what it's designed to solve.

1 Like

Thanks for the reply, Leo. Happy New Year.

Well, that certainly explains why nothing works when I tried testing the script just now! :joy:

There's nothing "wrong" with the Sync Left-to-Right command (i.e., it works how I would expect), but it enforces a left-to-right sync (again, as expected), which means I have to turn it off for those instances where I want a right-to-left sync, and then I have to remember to turn it back on again to avert disaster! As such, I just generally leave Sync Left-to-Right off.

So I would really like to have a warning when the left isn't the active Lister, but still perform a right-to-left sync after acknowledging the warning.

You could extend the button function to act ltr by default by control-clicking would perform standard sync (from active pane tp inactive one).

1 Like

Why not swap the sides when that’s needed? (There’s a button in the sync panel to do it, or use the one in the location bar, if it’s turned on.)

1 Like

Hmmm... yeah, that could work. I'll give that a try next time, to see how it works in a "real-world situation". Thanks for that suggestion, Leo! :+1: