Scripts (JS): Example Custom Column (Opus 11.6 & above)

This is an example custom column to demonstrate the new custom columns feature in Opus 11.6.

Place the attached .osp file into your Script AddIns folder (/dopusdata/Script AddIns).

You will then find the "Is Modified?" column in Folder Options in the new Script category.

// The OnInit function is called by Directory Opus to initialize the script add-in
function OnInit(initData) {

    // Provide basic information about the script by initializing the properties of the ScriptInitData object
    initData.name = "Is Modified Column";
    initData.desc = "Adds a column that indicates if a file has ever been modified.";
    initData.copyright = "(c) 2014 Jonathan Potter";
    initData.default_enable = true;
 

    // Create a new ScriptColumn object and initialize it to add the column to Opus
    var cmd = initData.AddColumn();
    cmd.name = "IsModified";
    cmd.method = "OnIsModified";
    cmd.label = "Is Modified?";
    cmd.autogroup = false;       // we provide our own grouping information
    cmd.autorefresh = true;      // auto-refresh column when file changes
    cmd.justify = "center";
    cmd.match.push_back("Yes");  // when searching, these are the only two options
    cmd.match.push_back("No");
}

// Implement the IsModified column (this entry point is an OnScriptColumn event).
// The name of this function must correspond to the value specified for the method property when the column was added in OnInit
function OnIsModified(scriptColData) {
 
    // scriptColData is a ScriptColumnData object. first check that this is the right column (it should be since we only added one)
    if (scriptColData.col != "IsModified")
        return;
 
    // we don't provide a value for folders since their timestamps don't mean much
    // we set the sort key to 3 so they come last (in case the user is mixing files and folders)
    if (scriptColData.item.is_dir) {

        scriptColData.value = "";
        scriptColData.sort = 3;
    }
 
    // for files, are the two dates the same?
    else if (new Date(scriptColData.item.create).valueOf() == new Date(scriptColData.item.modify).valueOf()) {

        scriptColData.value = "No";
        scriptColData.group = "Never Modified";
        scriptColData.sort = 2;
    }
 
    // the dates are different, therefore modified
    else {

        scriptColData.value = "Yes";
        scriptColData.group = "Modified";
        scriptColData.sort = 1;
    }
}

IsModifiedColumn.osp (1.04 KB)

It works and it is freakin' aweseome, did I tell you? o)

This is a great new feature. There have bee heaps of requests over the years this will now allow. Thanks.
This would be worth adding to the sample.

initData.min_version = "11.5.1"