I build a rename script that changes names based on the content of a text file, selected by the user. The problem happens when the preview is on, it also trigger the dialog for selecting the textfile. Then when it actually the rename happens, opens the dialog again, is there's a way to avoid that? For example, know if the script is running for the preview (no rename is done yet) or is the actual rename. Any though are welcome.
THanks.
THis is the code:
@script jscript
var textfile;
var line;
var linenumber = -1;
var cancel_open = false;
function OnGetNewName (G)
{
if (cancel_open)
return true;
linenumber++;
DOpus.Output("------------------------");
DOpus.Output("File:" + G.item);
DOpus.Output("newname:" + G.newname);
DOpus.Output(textfile);
if (!textfile)
{
DOpus.Output("textfile not defined!");
var item = DOpus.Dlg.Open("Select text file:", G.item.realpath);
if (!item.result)
{
cancel_open = true;
return true;
}
textfile = String(item);
DOpus.Output("textfile:" + textfile);
if (!DOpus.FSUtil.Exists(textfile))
{
DOpus.Output(textfile + " is not a valid text file!");
return true;
};
item = null;
};
if (!line)
{
var objStream = new ActiveXObject("ADODB.Stream");
with (objStream) {
CharSet = "utf-8";
Open();
LoadFromFile(textfile);
line = ReadText();
close();}
objStream = null;
line = line.replace(/\n{2,}/gi,"\n").replace("\\","/").replace("?","").replace('"',"'").replace(/ +/gi," ");
line = line.split(/\n+|\r\n+/g)
}
if (line[linenumber] == null)
return true;
var nuevo_nombre = G.newname.replace(/\[FILE\]/gi, line[linenumber]);
DOpus.Output(G.item + " renamed to " + nuevo_nombre);
return (nuevo_nombre + G.item.ext);
}
In the NEWNAME section, wherever the user places [FILE], will be replace with a line of the textfile, based of the number of files renamed.