> For the complete documentation index, see [llms.txt](https://chaoses-ib.gitbook.io/directory-opus/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chaoses-ib.gitbook.io/directory-opus/manual/scripting/example_scripts/adding_a_new_column.md).

# Adding a new Column

This is an example of a [script add-in](/directory-opus/manual/scripting/script_add-ins.md) that adds a new information column to Opus.

This column, **Is Modified?**, indicates whether a file has been modified since it was created. This is performed by simply comparing whether the item's creation and modification dates are the same.

* For files that have been modified, the column displays *Yes*, and for files that haven't been modified it displays *No*. Nothing is displayed for folders.
* When sorting by this column, modified files are displayed above non-modified files.
* When grouping by this column, the two groups are labeled *Modified* and *Never Modified*.

The basic procedure to add a custom column from a [script add-in](/directory-opus/manual/scripting/script_add-ins.md) is:

* Either:
  * In the [**OnInit**](/directory-opus/manual/reference/scripting_reference/scripting_events/oninit.md) event, create a \*\*[ScriptColumn](/directory-opus/manual/reference/scripting_reference/scripting_objects/scriptcolumn.md)\*\*object with the [**ScriptInitData**](/directory-opus/manual/reference/scripting_reference/scripting_objects/scriptinitdata.md)**.AddColumn** method.
  * Or, in the [**OnAddColumns**](/directory-opus/manual/reference/scripting_reference/scripting_events/onaddcolumns.md) event, create a \*\*[ScriptColumn](/directory-opus/manual/reference/scripting_reference/scripting_objects/scriptcolumn.md)\*\*object with the [**AddColData**](/directory-opus/manual/reference/scripting_reference/scripting_objects/addcoldata.md)**.AddColumn** method.
* Initialize the properties of the \*\*[ScriptColumn\*\*](/directory-opus/manual/reference/scripting_reference/scripting_objects/scriptcolumn.md)\*\*object. At a minimum you must populate the **name** and **method** properties. \* Create a separate function in your script-add in, with the **method** name you specified for the column. This method will be called when Opus wants to retrieve data for your column.

  // Set the script type to JScript to use this script // 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; // refresh column when files change 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; } }
