/////////////////////////////////////////////////////////////// // Apocalypse Columns // // based on Regex Columns Reloaded // // // // Add columns to Opus, using either // // - regex search against file name // // - other means // // // /////////////////////////////////////////////////////////////// /* ___ | | | | | | | | | | __! !__ \ / \ / \ / \ / Y ==> TO DEFINE THE COLUMNS, SCROLL ONE PAGE DOWN <== Full Tutorial: http://www.dearopus.com/filename-database.html */ // Opus calls OnInit to initialize the script add-in function OnInit(initData) { // basic information about the script initData.name = "Apocalypse Columns"; initData.desc = "Adds columns defined by regex search against filenames or other means."; initData.copyright = "playful 2015"; initData.min_version = "11.5.1" initData.version = "0.9"; initData.default_enable = true; // The following prefix is added to the column names when looking at columns in // the Folder Format panel, in order to distinguish the column from // similar columns from other scripts. // The prefix will not show in the actual column header var ColumnPrefix = "Apocalypse_"; // Add all columns (create ScriptColumn objects via AddColumn() // See http://www.gpsoft.com.au/help/opus11/index.html#!Documents/Scripting/ScriptColumn.htm for(var key in columns) { if (columns.hasOwnProperty(key)) { var column = columns[key]; var cmd = initData.AddColumn(); cmd.autorefresh = true; cmd.defsort = (typeof column.sort === 'undefined') || (column.sort != "DESC") ? 1 : -1; cmd.defwidth = (typeof column.width === 'undefined') ? 5 : column.width; cmd.header = key; cmd.infotiponly = (typeof column.infotiponly === 'undefined') ? false : column.infotiponly; cmd.justify = (typeof column.justify === 'undefined') ? "left" : column.justify; cmd.label = ColumnPrefix + key; cmd.method = "OnRegexColumn"; cmd.name = key; cmd.namerefresh = true; cmd.type = (typeof column.type === 'undefined') ? null : column.type; } } } // OnInit /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// ///// DEFINE YOUR COLUMNS HERE ///// /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// // Most columns will use a regex pattern, but you can also set columns // that don't use regex (see EXAMPLES OF NON-REGEX COLUMN below) // For the regex columns, you set several properties: // 1. "pattern", i.e. the regex pattern, // 2. "target" (optional), i.e. the subject for the regex (e.g. the file name, the extension: see TARGETS section below for details), // 3. "group" (optional), i.e. the capture group containing the column text (0 by default, i.e. the entire match) // 4. "width" (optional) to set the columns default width in characters. // 5. "justify" (optional), i.e. should the column be justified "left", "right", "center" or "path". The default is "left". // 6. "sort" (optional). When set to "DESC", if you click on the column to sort it, it will first sort in descending order // 7. "type" (optional). The column defaults to plain text, but it can also be set to number, double, size, zip, percent, igraph, date, time, datetime, stars // 8. "infotiponly" (optional): when set to true, the column will only dispay in file hover info tips, which are defined for file types in the file type editor // 9. "subjectPrefix" (optional): a string that gets preppended to the target string to form the regex subject. This is facility enables you to transform the text in the regex without writing a special column case. // 10. "returnTheFirstNonEmptyGroup" (optional): a Boolean (true/false) that indicates we should return the first group that is not-empty. Takes precedence over "group" // TARGETS // The regex pattern can be applied to several properties of the file item // We configure which property to run the regex on by setting "target" // Possible values for target: // 1. default: no value or "name_stem: (the file name without the extension) // 2. "realpath" (the pattern applies to the full pathname, i.e. path plus filename) // 3. "name" (the full file name including the extension) // 4. "ext" (the extension) // and more: see http://www.gpsoft.com.au/help/opus11/index.html#!Documents/Scripting/Item.htm var columns = { 'PID' : { pattern: /\[(PID_\d*)]/, group: 1 }, 'numid' : { pattern: /\[(\d*)\]/, group: 1 }, /////// EXAMPLES OF REGEX COLUMNS ////////// // You can delete these if you don't need them // Example column 'Title' : { // Everything to the left of the first "[" (left square bracket) pattern: /^(?:[^ ]| (?!\[))*/, }, // Example column to show the usage of GROUPS 'Area' : { // Area code in files that look like (212)456-7890 pattern: /^\((\d{3})/, group: 1 }, // Example column to show usage of the TARGET and WIDTH properties 'Path3' : { // Matches the first three charactes of the file's full path // The width property sets the column default display to four characters pattern: /^.{3}/, target: "realpath", width: 4 }, /////// EXAMPLES OF NON-REGEX COLUMN ////////// // You can delete these if you don't need them // Define the columns here (name, width if appropriate etc) // then add an "if" or "else if" case in the "First, handle special NON-REGEX Columns" section 'Namelen' : { // This column gives you the length of the file name }, 'Charsleft' : { // This column gives you the number of chars still available to use in the path + file name // Windows imposes a 260 maximum length for the Path+Filename }, /////// EXAMPLES OF TRICK COLUMNS //////////////// // You can delete these if you don't need them // For explanations, see www.dearopus.com/filename-database.html/filename-database.html#inspectiontrick // Trick Column, feel free to delete 'modify' : { // This column illustrates how you can display one of the file properties in a column pattern: /.*/, target: "modify" }, // Trick Column, feel free to delete '3-deep' : { // This column illustrates how you can create a Boolean column without creating a // special if case in the code pattern: /^(Y)(?:[^\\]*\\){4}/, target: "realpath", group: 1, subjectPrefix: "Y" }, // Trick Column, feel free to delete '3-deep YN' : { // This variation on the previous column not only displays "Y" if the path is at least // 3-deep, it displays "N" if it isn't pattern: /^Y(?=(?:[^\\]*\\){4})|N/, target: "realpath", subjectPrefix: "YN" }, // Trick Column, feel free to delete 'NumCapsLow' : { // This column shows "num" if a file stem is all numeric, "CAPS" if it is all uppercase, "low" if it is all lowercase pattern: /^(num)CAPSlow\d+$|^num(CAPS)low[A-Z]+$|^numCAPS(low)[a-z]+$/, subjectPrefix: "numCAPSlow", returnTheFirstNonEmptyGroup: true }, // Trick Column, feel free to delete 'pathdepth' : { // This column shows one of three values: "0-2" if a file's path depth is less than 3, "4-5", or "6+" pattern: /^0-2(3-5)6\+(?:[^\\]*\\){4,6}[^\\]*$|^0-23-5(6\+)(?:[^\\]*\\){7}|(0-2)/, target: "realpath", subjectPrefix: "0-23-56+", returnTheFirstNonEmptyGroup: true } }; /////////////////////////////////////////////////////////////// ///// END OF COLUMN DEFINITIONS ///// /////////////////////////////////////////////////////////////// function OnRegexColumn(ColumnData) { // OnRegexColumn is an OnScriptColumn method // See http://www.gpsoft.com.au/help/opus11/index.html#!Documents/Scripting/OnScriptColumn.htm // ColumnData is a ScriptColumnData object // See http://www.gpsoft.com.au/help/opus11/index.html#!Documents/Scripting/ScriptColumnData.htm var colName = ColumnData.col; if(!columns[colName]) return; ///////////////////////////////////////////////// //// First, handle special NON-REGEX Columns //// ///////////////////////////////////////////////// // Is this the filename length column? if (colName == 'Namelen') { ColumnData.value = ColumnData.item.name.length.toString(); } // Is this the "how many chars available in the filename" column? else if (colName == 'Charsleft') { var PathLength = new String(ColumnData.item.realpath).length; // how many chars available in the path + filename? Max = 260 ColumnData.value = (260-PathLength).toString(); } ///////////////////////////////////////////////// //// Next, handle REGEX Columns //// ///////////////////////////////////////////////// else { // it's a regex column var regexMatch; var fileSubject; var subject; // Did we specify a target, or are we matching on the default name_stem? if(!columns[colName].target) { fileSubject = ColumnData.item["name_stem"]; } else { fileSubject = ColumnData.item[columns[colName].target]; } // Add prefix to the subject if present subject = (typeof columns[colName].subjectPrefix === 'undefined') ? fileSubject : columns[colName].subjectPrefix + fileSubject; regexMatch = columns[colName].pattern.exec(subject); if (regexMatch != null) { // The general case: we have not set the returnTheFirstNonEmptyGroup property if (typeof columns[colName].returnTheFirstNonEmptyGroup === 'undefined') { // display the value for the correct capture group var capturegroup = (typeof columns[colName].group === 'undefined') ? 0 : columns[colName].group; ColumnData.value = regexMatch[capturegroup]; } else if(columns[colName].returnTheFirstNonEmptyGroup) { // What is the first non-empty group (apart from zero)? for(i = 1; i < regexMatch.length + 1; i++){ if (regexMatch[i] != '') { ColumnData.value = regexMatch[i]; break; } } } } } } // OnRegexColumn