Here's a simple script for comparing tab contents in dual display mode.
This script compares the files in source and destination tabs and selects the files that do no exist in other tab or differ by size.
By default only file names are compared and differences are selected. This is similar to the stock commands in the Edit > Select Other menu of Opus 12. But you can do some additional things with the script by adding arguments.
Use these arguments to change script behaviour:
- SIZE - compare file size
- CREATE - compare creation time
- MODIFY - compare modification time
- INVERT - select files that are same
Examples:
(There were screenshots here but the external URLs no longer work.)
CompareTabs
CompareTabs SIZE
CompareTabs SIZE CREATE
CompareTabs SIZE CREATE MODIFY
CompareTabs SIZE CREATE MODIFY INVERT
Download:
- Latest: v0.2 - Compare Tabs.js.txt (2.7 KB)
- Download the file, then drag it to the list under Preferences / Toolbars / Scripts.
Older, original version:
- Compare Tabs - OLD.js.txt (1.6 KB)
Script Code:
The script code for v0.2 is reproduced below, for easy reference:
/*
Compare tabs in dual display mode (requires DOpus version >=11.0.9)
By default only file name is compared and differences are selected.
Use these arguments to change script behaviour:
SIZE - compare file size
CREATE - compare creation time
MODIFY - compare modification time
INVERT - select files that are same
*/
function OnInit(data) {
var cmd = data.AddCommand();
data.version = "v0.2";
cmd.name = "CompareTabs";
cmd.method = "OnCompareTabs";
cmd.label = data.name = "Compare Tabs";
cmd.desc = data.desc = "Compare tabs in dual display mode.";
cmd.template = "SIZE/S,CREATE/S,MODIFY/S,INVERT/S";
data.default_enable = true;
return false;
}
function OnCompareTabs(data) {
if (!data.func.desttab) return; // do nothing if not in dual panel mode
var src = {}, dst = {}, srcdup = {}, dstdup = {};
// add all files from source tab to src array
var srcEnum = new Enumerator(data.func.sourcetab.files);
while (!srcEnum.atEnd()) {
var item = srcEnum.item();
src[item.name] = item;
srcEnum.moveNext();
}
// add different files from destination tab to dst array and others to dstdup array
var dstEnum = new Enumerator(data.func.desttab.files);
while (!dstEnum.atEnd()) {
item = dstEnum.item();
var isDuplicate = item.name in src;
if (isDuplicate && data.func.args.got_arg.size) isDuplicate = src[item.name].size - item.size == 0;
if (isDuplicate && data.func.args.got_arg.create) isDuplicate = src[item.name].create - item.create == 0;
if (isDuplicate && data.func.args.got_arg.modify) isDuplicate = src[item.name].modify - item.modify == 0;
if (isDuplicate) dstdup[item.name] = item;
else dst[item.name] = item;
dstEnum.moveNext();
}
// move duplicates from src array to srcdup array
for (var k in src) if (k in dstdup) {
srcdup[k] = src[k];
delete src[k];
}
// add files from src or srcdup to select command depending on INVERT argument
data.func.command.ClearFiles();
if (data.func.args.got_arg.invert) for (k in srcdup) data.func.command.AddFile(srcdup[k]);
else for (k in src) data.func.command.AddFile(src[k]);
data.func.command.RunCommand("Select FROMSCRIPT DESELECTNOMATCH");
// add files from dst or dstdup to select command depending on INVERT argument
data.func.command.SetSourceTab(data.func.desttab);
data.func.command.ClearFiles();
if (data.func.args.got_arg.invert) for (k in dstdup) data.func.command.AddFile(dstdup[k]);
else for (k in dst) data.func.command.AddFile(dst[k]);
data.func.command.RunCommand("Select FROMSCRIPT DESELECTNOMATCH");
}