Hi all,
First post in the forum! Here's a script I've been using to keep track of old versions of files or documents, particularly big binary files that don't compress well like lossy image formats or the (already) compressed XML MS office formats. I've found this pretty handy for cases where I don't want to bother with dealing with git-lfs. The script copies selected files into a time-stamped subfolder and logs their names + a commit message into a TOML file that can be read by other programs. Cheers!
Script code for reference:
function OnClick(clickData) {
DOpus.ClearOutput();
var cmd = clickData.func.command;
cmd.deselect = false; // Prevent automatic deselection
cmd.RunCommand("CreateFolder Versions");
var mydate = DOpus.Create.Date().Format("D#yyyy-MM-dd");
var mytime = DOpus.Create.Date().Format("T#hh-mm-ss");
var dt = "D" + mydate + "-T" + mytime;
DOpus.Output(mydate);
// archive_file = "Version-" + dt + ".zip";
archive_folder = "Version-" + dt;
archive_path = "Versions\\" + archive_folder;
var dlg = DOpus.Dlg;
dlg.window = clickData.func.sourcetab;
dlg.template = "Message"
dlg.Show();
var message = dlg.Control("msgEdit").value
DOpus.Output(message);
DOpus.Output("Return code = " + dlg.result);
if (dlg.result == 0) {
return;
}
var sourcepath = DOpus.FSUtil.Resolve(clickData.func.sourcetab.path);
fso = new ActiveXObject("Scripting.FileSystemObject");
var listing_path = sourcepath + "\\Versions\\Listing.toml"
DOpus.Output(listing_path);
CreateFile = true;
ForAppending = 8;
CreateFile = true;
f1 = fso.OpenTextFile(listing_path, ForAppending, CreateFile);
f1.Write("[versions." + dt + "]\r");
f1.Write("archive = \"" + archive_folder + "\"\r");
if (message.length > 0) {
f1.Write("message = \"" + message + "\"\r");
}
f1.Write("files = [\r");
// --------------------------------------------------------
if (clickData.func.sourcetab.selected.count > 0) {
for (var eSel = new Enumerator(clickData.func.sourcetab.selected); !eSel.atEnd(); eSel.moveNext()) {
var fpath = eSel.item().RealPath + ""; // force string type
DOpus.Output("file: " + fpath);
f1.Write(" \"" + fpath.replace(/\\/g,"/") + "\",\r");
}
}
f1.Write("]\r\r");
DOpus.Output(cmd.RunCommand("Copy UNATTENDED=yes CREATEFOLDER=" + archive_path + " HERE"));
}
<resources>
<resource name="Message" type="dialog">
<dialog fontsize="8" height="58" lang="english" standard_buttons="ok,cancel" width="177">
<control halign="left" height="8" name="static1" title="Commit Message" type="static" width="60" x="7" y="7" />
<control halign="left" height="13" name="msgEdit" type="edit" width="168" x="5" y="22" />
</dialog>
</resource>
</resources>