×

VCOO0007

OmniOutliner: Add Numeric Column

This command will add a new column formatted to display numeric content. If a single column is selected when the command is invoked, the new column will be added after the selected column, otherwise the new column is appended to end (right) of the current columns.

Scope and Syntax

Language: English (United States 🇺🇸 · Great Britain 🇬🇧 · Australia 🇦🇺 · Canada 🇨🇦)

Scope: OmniOutliner

Command phrase variations (words in [brackets] are optional):

Requirements

Video: Add Numeric Column
Add a new column formatted to display numeric content.
Video: Add Numeric Column
Add a new column formatted to display numeric content.

Downloads

Script Code

If a single column is selected when the command is invoked, the new column will be added after the selected column, otherwise the new column is appended to end (right) of the current columns.

The command presents a form dialog with the following controls for setting the parameters for the created column.

Form dialog for the Add Numeric Column command

 1  Column Title • The title for the new column. The width of the column is determined by the length of the column title.

 2  Text Alignment • The text alignment options to apply to the column text: Left, Center, Right, Justified, and Natural.

 3  Numeric Format • The formatting to be applied to the numeric values: Plain (123), Decimal (123.45), Percent (123%), Decimal Percent (123.45), Decimal Separators (1,234.12), Localized Currency

 4  Fitting Column • If this option is selected, the width of the column will be subtracted from the topic column to make room for the added column to fit in the window document view.

Here is the script code:

Add Numeric Column


(async () => { try { function createUtterance(textToSpeak){ AlexID = ( (app.platformName === "macOS") ? "com.apple.speech.synthesis.voice.Alex" : "com.apple.speech.voice.Alex" ) voiceObj = Speech.Voice.withIdentifier(AlexID) voiceRate = 0.4 utterance = new Speech.Utterance(textToSpeak) utterance.voice = voiceObj utterance.rate = voiceRate return utterance } var synthesizer = new Speech.Synthesizer() try {document.name} catch(err){ throw {name:"Missing Resource",message:"No outline document is open."} } var inputForm = new Form() textInputField = new Form.Field.String( "columnTitle", "Title", null ) alignmentMenu = new Form.Field.Option( "alignmentValue", "Align", TextAlignment.all, null, TextAlignment.all[2] ) formats = ["Plain (123)", "Decimal (123.00)", "Percent (123%)", "Decimal Percent (123.12%)", "Decimal Separators (1,234.12)", "Currency"] formatMenu = new Form.Field.Option( "formatType", "Format", [0, 1, 2, 3, 4, 5], formats, 0 ) checkSwitchField = new Form.Field.Checkbox( "shouldCompensate", "Compensate by reducing the topic width", true ) inputForm.addField(textInputField) inputForm.addField(alignmentMenu) inputForm.addField(formatMenu) inputForm.addField(checkSwitchField) inputForm.validate = function(formObject){ columnTitle = formObject.values['columnTitle'] textStatus = (columnTitle && columnTitle.length > 0) ? true:false return textStatus } formPrompt = "Column title, alignment, and format:" formButtom = "Add" spokenPrompt = "Please indicate the column title, alignment, and format." utterance = createUtterance(spokenPrompt) synthesizer.speakUtterance(utterance) formObject = await inputForm.show(formPrompt, formButtom) var columnTitle = formObject.values['columnTitle'] var alignmentValue = formObject.values['alignmentValue'] var formatType = formObject.values['formatType'] var shouldCompensate = formObject.values['shouldCompensate'] switch(formatType) { case 0: var fmtr = Formatter.Decimal.plain break; case 1: var fmtr = Formatter.Decimal.decimal break; case 2: var fmtr = Formatter.Decimal.percent break; case 3: var fmtr = Formatter.Decimal.percentWithDecimal break; case 4: var fmtr = Formatter.Decimal.thousandsAndDecimal break; case 5: var fmtr = Formatter.Decimal.currency() break; default: var fmtr = Formatter.Decimal.plain break; } var tree = document.outline var editor = document.editors[0] selectedCols = editor.selection.columns if(selectedCols.length === 1){ var targetColumn = selectedCols[0] } else { var targetColumn = null } // calculate the new column width based upon title and font size titleFontSize = tree.columnTitleStyle.get(Style.Attribute.FontSize) pfmtr = Formatter.Decimal.plain fontSize = parseInt(pfmtr.stringFromDecimal(titleFontSize)) var columnWidth = (columnTitle.length * fontSize) columnWidth = (columnWidth >= 36) ? columnWidth : 36 tree.addColumn( Column.Type.Number, editor.afterColumn(targetColumn), column => { column.title = columnTitle editor.setWidthForColumn(column, columnWidth) column.style.set(Style.Attribute.ParagraphAlignment, alignmentValue) column.formatter = fmtr if(shouldCompensate){ currentWidth = editor.widthForColumn(tree.outlineColumn) newWidth = currentWidth - columnWidth if(newWidth > 36){ editor.setWidthForColumn(tree.outlineColumn, newWidth) } } } ) utterance = createUtterance("Done!") synthesizer.speakUtterance(utterance) } catch(err){ if(!err.causedByUserCancelling){ utterance = createUtterance(err.message) synthesizer.speakUtterance(utterance) //new Alert(err.name, err.message).show() } } })();

 

 

 

LEGAL

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Mention of third-party websites and products is for informational purposes only and constitutes neither an endorsement nor a recommendation. OMNI-AUTOMATION.COM assumes no responsibility with regard to the selection, performance or use of information or products found at third-party websites. OMNI-AUTOMATION.COM provides this only as a convenience to our users. OMNI-AUTOMATION.COM has not tested the information found on these sites and makes no representations regarding its accuracy or reliability. There are risks inherent in the use of any information or products found on the Internet, and OMNI-AUTOMATION.COM assumes no responsibility in this regard. Please understand that a third-party site is independent from OMNI-AUTOMATION.COM and that OMNI-AUTOMATION.COM has no control over the content on that website. Please contact the vendor for additional information.