Good afternoon everyone. I'm having a very small but annoying issue with a script I created which may be a bug or just an option I'm missing. Below is the script:
@script:jscript
function OnClick(clickData)
{
var cmd = clickData.func.command;
cmd.deselect = false;
var tab = clickData.func.sourcetab;
var filepath = "J:\\Work\\rejected.txt";
var encoding = "utf-8";
var file = DOpus.FSUtil.OpenFile(filepath, "wo");
if (file.error == 0){
cmd.clear;
var i = 0;
for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {
file.seek(0, "e")
file.write("\n" + "[Obj] " + tab.selected_files(i).name_stem + " " + DOpus.FSUtil.Hash(tab.selected_files(i), "md5"));
if (DOpus.fsUtil.exists(tab.selected_files(i).realpath)){
cmd.runCommand("Delete " + '"' + tab.selected_files(i).realpath + '"');
} else {
DOpus.output("Error, cannot find and delete the following file: " + tab.selected_files(i).realpath);
}
i++;
}
cmd.clear;
i = 0;
for (var e = new Enumerator(tab.selected_dirs); !e.atEnd(); e.moveNext()) {
file.seek(0, "e")
file.write("\n" + "[ObjGrp] " + tab.selected_dirs(i).name_stem);
if (DOpus.fsUtil.exists(tab.selected_dirs(i).realpath)){
cmd.runCommand("Delete " + '"' + tab.selected_dirs(i).realpath + '"');
} else {
DOpus.output("Error, cannot find and delete the following file: " + tab.selected_dirs(i).realpath);
}
i++;
}
}
file.close;
}
Everything in this script works as intended except for the fact that when I right click on a file and click on the context menu item to execute it, the script will be executed on the file where my mouse was when clicking on the context menu item and not on the item I right clicked. This seems to happen whether I have cmd.deselect = false; in there or not, which is supposed to prevent item deselection.
I'm not sure if this is a factor but I use single click mode. Given that hovering in single click mode selects a file it's possible that somehow the file the mouse hovers over at the time of clicking the context menu item is stealing focus and thus it instead is being operated on instead of the intended file.