This script merges the tags of the selected items (files and folders) in the source with those in the destination that have the same name. The tags will be unique, sorted alphabetically, and written to both files of a pair.
The script will work in collections, but not in Flatview.
In this published version, the script will only show the command it is going to run, but not execute it. Uncomment the last line in the script, to really modify the files.
Not sure what tags are?
https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Keywords_for_SetAttr_META.htm
// https://resource.dopus.com/t/sync-tags-between-files/41616
// 2022-07-02
function OnClick(clickData) {
var cmd = clickData.func.command;
var tab = clickData.func.sourcetab;
var dtab = clickData.func.desttab;
var fsu = DOpus.FSUtil();
var tagSet = DOpus.Create().StringSet();
var tagVec = DOpus.Create().Vector();
cmd.deselect = false;
if (!dtab) return;
cmd.RunCommand('Set UTILITY=otherlog');
DOpus.ClearOutput();
DOpus.Output('Enumerating...\n');
for (var e = new Enumerator(tab.selected); !e.atEnd(); e.moveNext()) {
var srcItem = e.item();
if (srcItem.metadata == 'none') continue;
var destItem = fsu.GetItem(fsu.Resolve(dtab.path + '\\' + srcItem.name));
if (!fsu.Exists(destItem)) continue;
if (destItem.metadata == 'none') continue;
DOpus.Output(srcItem);
DOpus.Output(destItem);
tagVec.assign(srcItem.metadata.tags);
tagVec.append(destItem.metadata.tags);
tagVec.sort();
tagSet.assign(tagVec); // remove duplicates
var tagString = '';
for (var ee = new Enumerator(tagSet); !ee.atEnd(); ee.moveNext()) {
tagString += ee.item() + ';';
}
tagString = tagString.substring(0, tagString.length - 1);
cmd.ClearFiles();
cmd.AddFile(srcItem);
cmd.AddFile(destItem);
var cmdLine = ('SetAttr META "tags:' + tagString + '"');
DOpus.Output(cmdLine);
DOpus.Output('');
// Un-comment the next line, if you think the script does the right thing
// cmd.RunCommand(cmdLine);
}
DOpus.Output('\n... done.');
}
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>SyncTags</label>
<icon1>#properties</icon1>
<function type="script">
<instruction>@script JScript</instruction>
<instruction>// https://resource.dopus.com/t/sync-tags-between-files/41616</instruction>
<instruction />
<instruction>// 2022-07-02</instruction>
<instruction />
<instruction>function OnClick(clickData) {</instruction>
<instruction> var cmd = clickData.func.command;</instruction>
<instruction> var tab = clickData.func.sourcetab;</instruction>
<instruction> var dtab = clickData.func.desttab;</instruction>
<instruction> var fsu = DOpus.FSUtil();</instruction>
<instruction> var tagSet = DOpus.Create().StringSet();</instruction>
<instruction> var tagVec = DOpus.Create().Vector();</instruction>
<instruction />
<instruction> cmd.deselect = false;</instruction>
<instruction />
<instruction> if (!dtab) return;</instruction>
<instruction />
<instruction> cmd.RunCommand('Set UTILITY=otherlog');</instruction>
<instruction> DOpus.ClearOutput();</instruction>
<instruction />
<instruction> DOpus.Output('Enumerating...\n');</instruction>
<instruction />
<instruction> for (var e = new Enumerator(tab.selected); !e.atEnd(); e.moveNext()) {</instruction>
<instruction> var srcItem = e.item();</instruction>
<instruction> if (srcItem.metadata == 'none') continue;</instruction>
<instruction />
<instruction> var destItem = fsu.GetItem(fsu.Resolve(dtab.path + '\\' + srcItem.name));</instruction>
<instruction> if (!fsu.Exists(destItem)) continue;</instruction>
<instruction> if (destItem.metadata == 'none') continue;</instruction>
<instruction />
<instruction> DOpus.Output(srcItem);</instruction>
<instruction> DOpus.Output(destItem);</instruction>
<instruction />
<instruction> tagVec.assign(srcItem.metadata.tags);</instruction>
<instruction> tagVec.append(destItem.metadata.tags);</instruction>
<instruction> tagVec.sort();</instruction>
<instruction> tagSet.assign(tagVec); // remove duplicates</instruction>
<instruction />
<instruction> var tagString = '';</instruction>
<instruction> for (var ee = new Enumerator(tagSet); !ee.atEnd(); ee.moveNext()) {</instruction>
<instruction> tagString += ee.item() + ';';</instruction>
<instruction> }</instruction>
<instruction> tagString = tagString.substring(0, tagString.length - 1);</instruction>
<instruction />
<instruction> cmd.ClearFiles();</instruction>
<instruction> cmd.AddFile(srcItem);</instruction>
<instruction> cmd.AddFile(destItem);</instruction>
<instruction />
<instruction> var cmdLine = ('SetAttr META "tags:' + tagString + '"');</instruction>
<instruction> DOpus.Output(cmdLine);</instruction>
<instruction> DOpus.Output('');</instruction>
<instruction> // Un-comment the next line, if you think the script does the right thing</instruction>
<instruction> // cmd.RunCommand(cmdLine);</instruction>
<instruction> }</instruction>
<instruction />
<instruction> DOpus.Output('\n... done.');</instruction>
<instruction>}</instruction>
</function>
</button>