Using this script column from the forum
Age column
//v1.3 - 4 September 2021
//- added config options to set both auto-calculated Age Created and Age Modified column decimal place accuracy
//- renamed columns
//v1.2 - 10 December 2016
//- split columns out into auto and unit options, rather than config options
//v1.1 - 9 December 2016
//- updated to work with multicol appropriately (thanks tbone!)
//v1.0 - 27 November 2016
//- initial release based on tbone's ModifiedWithin column script (http://resource.dopus.com/viewtopic.php?f=35&t=23192)
/*
can put your columns into the main categories now,
Don't think it's fully documented yet,
but with script columns it's set via ScriptColumn.category,
which takes one of these string values:
"loc"
"date"
"size"
"std"
"dims"
"image"
"music"
"prog"
"doc"
"movie"
"sums"
"script"
"shell"
"other"
"eval"
*/
//==================================================
function OnInit(data)
{
//uid added via script wizard (do not change after publishing this script)
var uid = "4CBC870D-C8E5-435F-8F68-FA1AA7E16DBB";
//resource center url added via script wizard (required for updating)
var url = ""
data.name = "Age";
data.group = "Columns";
data.desc = "Adds sortable columns that indicate folder/file age since creation or modification"
data.copyright = "(c) 2016 Chuck"
data.url = "http://resource.dopus.com/viewtopic.php?f=35&t=28433"
data.version = "1.3"
data.min_version = "12.24"
data.default_enable = true;
//==================================================
function ConfigHelper(data)
{
this.data=data; this.descriptions=null; this.last=null;
this.add = function(name, val, description)
{
this.data.config[name]=val; this.last=[this.data.config[name],name];
if (description!=undefined) this.des(description); return this;
}
this.des = function(description)
{
if (!(description && DOpus.version.AtLeast("11.6.1"))) return this;
if (!this.descriptions)
{
this.descriptions=DOpus.NewMap();
data.config._descriptions=this.descriptions;
}
this.descriptions(this.last[1])=description; return this;
}
this.val = function(val)
{
if (typeof this.last[0]=="object") this.last[0].push_back(val);
else this.last[0]=val; return this;
}
}
//==================================================
var cfg = new ConfigHelper(data);
cfg.add("Column.Width", "60px").des("Standard column width");
cfg.add("Column.Justify", DOpus.Create.Vector()).des("Column text alignment right, left or center").val(0).val("right").val("left").val("center");
cfg.add("Accuracy_Auto_Created", "0").des("Decimal place accuracy for automatically calculated Age-Created column");
cfg.add("Accuracy_Auto_Modified", "0").des("Decimal place accuracy for automatically calculated Age-Modified column");
}
//==================================================
function OnAddColumns(data)
{
var cmd = data.AddColumn();
cmd.multicol = true;
cmd.name = "TimeSinceModified";
cmd.label = "- Age : Time Since Modification (Auto)";
cmd.header = "Age (modified)";
cmd.category = "date";
cmd.method = "Auto";
cmd.autorefresh = true;
cmd.namerefresh = true;
cmd.defwidth = Script.config["Column.Width"];
cmd.type = "text";
var justify = ["right","left","center"]
cmd.justify = justify[Script.config["Column.Justify"]];
var cmd = data.AddColumn();
cmd.multicol = true;
cmd.name = "TimeSinceCreated";
cmd.label = "- Age : Time Since Creation (Auto)";
cmd.header = "Age (created)";
cmd.category = "date";
cmd.method = "Auto";
cmd.autorefresh = true;
cmd.namerefresh = true;
cmd.defwidth = Script.config["Column.Width"];
cmd.type = "text";
var justify = ["right","left","center"]
cmd.justify = justify[Script.config["Column.Justify"]];
var cmd = data.AddColumn();
cmd.multicol = true;
cmd.name = "TimeSinceModifiedUnits";
cmd.label = "- Age : Time Since Modification (Units)";
cmd.header = "Age (modified)";
cmd.category = "date";
cmd.method = "Units";
cmd.autorefresh = true;
cmd.namerefresh = true;
cmd.defwidth = Script.config["Column.Width"];
cmd.type = "text";
var justify = ["right","left","center"]
cmd.justify = justify[Script.config["Column.Justify"]];
var cmd = data.AddColumn();
cmd.multicol = true;
cmd.name = "TimeSinceCreatedUnits";
cmd.label = "- Age : Time Since Creation (Units)";
cmd.header = "Age (created)";
cmd.category = "date";
cmd.method = "Units";
cmd.autorefresh = true;
cmd.namerefresh = true;
cmd.defwidth = Script.config["Column.Width"];
cmd.type = "text";
var justify = ["right","left","center"]
cmd.justify = justify[Script.config["Column.Justify"]];
}
//==================================================
function Auto(data)
{
var dateMod = new Date(data.item.modify).valueOf();
var dateCre = new Date(data.item.create).valueOf();
var dateNow = new Date().valueOf();
var diffCre = (dateNow-dateCre)/60000;
var diffMod = (dateNow-dateMod)/60000;
var accuracy_ac = Number(Script.config["Accuracy_Auto_Created"]);
var accuracy_am = Number(Script.config["Accuracy_Auto_Modified"]);
//setting defaults (no value to clutter columns)
data.columns("TimeSinceCreated").value = "---";
data.columns("TimeSinceModified").value = "---";
//Determine age in minutes since file/folder created and add appropriate suffix to calculation
if (diffCre < 60)
{
data.columns("TimeSinceCreated").value = (diffCre).toFixed(0) + " min";
}
else if (diffCre < 1440)
{
data.columns("TimeSinceCreated").value = ((diffCre)/60).toFixed(accuracy_ac) + " hrs";
}
else if (diffCre < 525960)
{
data.columns("TimeSinceCreated").value = ((diffCre)/1440).toFixed(accuracy_ac) + " days";
}
else
{
data.columns("TimeSinceCreated").value = ((diffCre)/525960).toFixed(accuracy_ac) + " yrs";
}
data.columns("TimeSinceCreated").sort = diffCre;
//Determine age in minutes since file/folder modified and add appropriate suffix to calculation
if (diffMod < 60)
{
data.columns("TimeSinceModified").value = (diffMod).toFixed(0) + " min";
}
else if (diffMod < 1440)
{
data.columns("TimeSinceModified").value = ((diffMod)/60).toFixed(accuracy_am) + " hrs";
}
else if (diffMod < 525960)
{
data.columns("TimeSinceModified").value = ((diffMod)/1440).toFixed(accuracy_am) + " days";
}
else
{
data.columns("TimeSinceModified").value = ((diffMod)/525960).toFixed(accuracy_am) + " yrs";
}
data.columns("TimeSinceModified").sort = diffMod;
}
//==================================================
function Units(data)
{
var dateMod = new Date(data.item.modify).valueOf();
var dateCre = new Date(data.item.create).valueOf();
var dateNow = new Date().valueOf();
var diffCre = (dateNow-dateCre)/60000;
var diffMod = (dateNow-dateMod)/60000;
var y = d = h = m = sc = sm = 0;
//setting defaults (no value to clutter columns)
data.columns("TimeSinceCreatedUnits").value = "---";
data.columns("TimeSinceModifiedUnits").value = "---";
//Determine age since file/folder created and add appropriate suffix to calculation
sc = (dateNow-dateCre)/1000;
switch (true)
{
case (sc > 31557600):
y = Math.floor(sc / 31557600);
sc %= 31557600;
case (sc > 86400):
d = Math.floor(sc / 86400);
sc %= 86400;
case (sc > 3600):
h = Math.floor(sc / 3600);
sc %= 3600;
case (sc > 60):
m = Math.floor(sc / 60);
sc %= 60;
sc = sc.toFixed(0);
case (sc >= 0):
m = 0;
sc = 0;
sc = sc.toFixed(0);
}
//Determine age since file/folder modified and add appropriate suffix to calculation
sm = (dateNow-dateMod)/1000;
switch (true)
{
case (sm > 31557600):
y = Math.floor(sm / 31557600);
sm %= 31557600;
case (sm > 86400):
d = Math.floor(sm / 86400);
sm %= 86400;
case (sm > 3600):
h = Math.floor(sm / 3600);
sm %= 3600;
case (sm > 60):
m = Math.floor(sm / 60);
sm %= 60;
sm = sm.toFixed(0);
}
//Correct numbers < 10 to add leading 0
var yy = y.toString();
var dd = d.toString();
var hh = h.toString();
var mm = m.toString();
var ssc = sc.toString();
var ssm = sm.toString();
yy = yy.replace(yy, (y < 10) ? "0" + y : y);
dd = dd.replace(dd, (d < 10) ? "0" + d : d);
dd = dd.replace(dd, (dd < 100) ? "0" + dd : dd); //add second leading 0 since may have > 99 days
hh = hh.replace(hh, (h < 10) ? "0" + h : h);
mm = mm.replace(mm, (m < 10) ? "0" + m : m);
ssc = ssc.replace(ssc, (sc < 10) ? "0" + sc : sc);
ssm = ssm.replace(ssm, (sm < 10) ? "0" + sm : sm);
//Format columns to display
var fc = yy + ':' + dd + ':' + hh + ':' + mm + ':' + ssc;
data.columns("TimeSinceCreatedUnits").value = fc;
data.columns("TimeSinceCreatedUnits").sort = diffCre;
var fm = yy + ':' + dd + ':' + hh + ':' + mm + ':' + ssm;
data.columns("TimeSinceModifiedUnits").value = fm;
data.columns("TimeSinceModifiedUnits").sort = diffMod;
}
//==================================================
function OnScriptConfigChange(data)
{
Script.InitColumns();
Script.RefreshColumn("TimeSinceCreated");
Script.RefreshColumn("TimeSinceModified");
Script.RefreshColumn("TimeSinceCreatedUnits");
Script.RefreshColumn("TimeSinceModifiedUnits");
}
///////////////////////////////////////////////////////////////////////////////
function OnAboutScript(data)
{ //v0.1
var cmd = DOpus.Create.Command();
if (!cmd.Commandlist('s').exists("ScriptWizard"))
{
if (DOpus.Dlg.Request("The 'ScriptWizard' add-in has not been found.\n\n" +
"Install 'ScriptWizard' from [resource.dopus.com].\nThe add-in enables this dialog and also offers " +
"easy updating of scripts and many more.","Yes, take me there!|Cancel", "No About.. ", data.window))
cmd.RunCommand('http://resource.dopus.com/viewtopic.php?f=35&t=23179');
}
else
cmd.RunCommand('ScriptWizard ABOUT WIN='+data.window+' FILE="'+Script.File+'"');
}
//MD5 = "8f56f14954a42d94d8c5cd5181afb987"; DATE = "2016.12.09 - 20:17:45"
gives these results when new files are added (using a batch scaling routine in this case) (rightmost column)
the scaling routine is creating a .tmp file first then that gets updated to a .png file.
As you can see some files do not get updated by the script column and some do (refreshing does fix this but is an additional unnecessary step in the workflow) - indicating some internal glitch as there seems to be nothing wrong with the code.