Onetastic Macro Documentation
Onetastic Macro Documentation
Welcome
Welcome to Onetastic Macro Documentation. Start with one of the following topics:
Macro Structure
A macro consist of a list of statements which may look like this:
https://getonetastic.com/docs/OnetasticMacroDocumentation 1/156
11/11/24, 2:09 PM Onetastic Macro Documentation
The above macro will highlight all paragraphs that is last edited by someone named John.
Macro Editor
User Interface
Menus and Toolbar
Editing Macros
Macro Debugging
Macro Editor
Macro Editor can be accessed from Edit Macros and New Macro buttons on the ribbon. It can be used for:
User Interface
https://getonetastic.com/docs/OnetasticMacroDocumentation 2/156
11/11/24, 2:09 PM Onetastic Macro Documentation
See Menus and Toolbar for an explanation of how to use the editor
Menus contain all these buttons and additional items for editing the macro:
File
New Ctrl+N Closes the current macro and creates a new empty one
https://getonetastic.com/docs/OnetasticMacroDocumentation 3/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Edit Macro Info... Displays the Edit Macro Info dialog
Share on Macroland... Starts the process to upload the current macro to Macroland
Edit
Edit in VSCode F2 Opens the configured default external editor to edit the macro
Manage External Editors... Displays the Manage External Editors dialog
View
Object Browser Ctrl+J Displays or hides the Object Browser to see object hierarchy
Storage
Show Local Storage Opens Object Browser to display the local storage for this macro
Clear Local Storage Deletes any local storage for this macro
Edit Binary Storage Opens the Binary Store dialog to edit binary storage for this
macro
Debug
Start Debugging F10 Starts the current macro under the debugger
Run under Debugger F5 Runs the current macro under the debugger
Menu
Create Macro Menu Creates a Setup function for this macro or switches to it if it
already exists
Debug Menu Item > Runs a menu item for the current macro under the debugger
Run Menu Item under Debugger > Runs a menu item for the current macro under the debugger
Run Menu Item > Runs a menu item for the current macro
https://getonetastic.com/docs/OnetasticMacroDocumentation 4/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Tools
Help
Editing Macros
Macro Editor allows you to inspect existing macro code and debug them. To edit macros it integrates with
external code editors. Macro Editor comes with built in support for popular code editors like VSCode and
NotePad++. When opening a macro, Macro Editor will offer opening the macro with an external editor of your
choice:
Once you open the macro in the external editor, you can now edit the macro and as you save the file in the
external editor, Macro Editor will import and update the current macro. If you prefer a different editor than
available in this list, you can click on the button to add a new external editor and use that.
You can also use the toolbar or menus of Macro Editor, or the F2 shortcut to open your macros in an external
editor for editing your macros. In the Edit menu, the following options provide access to this functionality:
Edit
Edit in VSCode F2 Opens the configured default external editor to edit the macro
Find Ctrl+F
Find Next F3
In the toolbar the first button is used to launch external editors or manage them:
https://getonetastic.com/docs/OnetasticMacroDocumentation 5/156
11/11/24, 2:09 PM Onetastic Macro Documentation
https://getonetastic.com/docs/OnetasticMacroDocumentation 6/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Here you can add, remove, and change the order of external editors.
Macro Debugging
Macro Editor allows running macros step by step under the debugger via the
Debug > Start Debugging (F10) command or the Debug > Run under Debugger (F5) command. This will
switch the editor into the debugger mode and will display the next statement with a yellow background, activate
the Object Browser with local variables:
https://getonetastic.com/docs/OnetasticMacroDocumentation 7/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Once in the debugger mode, you can step through the macro and see the local variables in the Object Browser.
Following menu and toolbar will appear in debug mode:
Debug
Breakpoints
https://getonetastic.com/docs/OnetasticMacroDocumentation 8/156
11/11/24, 2:09 PM Onetastic Macro Documentation
You can set a breakpoint on a statement using Toggle Breakpoint button or the F9 key. This works both in the
editor and in the debugger. The statements with a breakpoint will show with a maroon background and the
debugger will stop when it hits one of the breakpoints.
Object Browser
Macro Debugger automatically displays the Object Browser on the right. Object Browser allows browsing
OneNote hierarchy under Current Page, Section, Section Group, Notebook and under all notebooks. This way you
can look into how the objects and their properties are stored in OneNote. This is also useful while editing a macro
and can be activated using View > Object Browser (Ctrl+J). Object Browser displays local variables currently
in use in the macro under Locals section, allowing you to see the types and values of them.
Demonstration
Watch the short video here to learn more about how to use these tools.
How To
Using variables
Finding and modifying objects
Creating new page content
Asking for user input
Storing persistent data
Using binary data
Sorting objects
Macro menus
Bulleted and numbered lists
Sample Macros
Using variables
Macro language has variables, for temporarily storing and manipulating information. Variables can be of various
types including objects and arrays. Variables are named with a dollar sign ($) followed by an identifier. The valid
characters in the variable name are a-z, A-Z, 0-9 and underscore (_). Following macro demonstrate use of
variables to store the list of cells in a page and to store the text of the first cell to fill the rest of the cells with:
Here $Cells, $Cell, $i, $TextOfFirstCell are all variables storing an array of Cell objects, a Cell object, an integer,
and a string respectively.
// You can also access the notebook root which stores all the notebooks
$NotebookRoot = GetNotebookRoot()
// Once you have an object, you can go up to find its parent or ancestors
$FirstOnetastic = $AllInstancesOfTheWordOnetastic[0]
if (GetParentOfType($FirstOnetastic, "Paragraph", $ParentParagraph))
// Found the parent paragraph
if (GetAncestorOfType($FirstOnetastic, "Notebook", $ContainingNotebook))
// Found the containing notebook
https://getonetastic.com/docs/OnetasticMacroDocumentation 10/156
11/11/24, 2:09 PM Onetastic Macro Documentation
// Modify the section name and color
$CurrentSection = GetCurrentSection()
$CurrentSection.name = "new name"
$CurrentSection.color = "yellow"
functions to create the new objects. After creating each object, you can modify its properties or create more
content below it:
https://getonetastic.com/docs/OnetasticMacroDocumentation 11/156
11/11/24, 2:09 PM Onetastic Macro Documentation
$Text = InsertObject($Paragraph, "Text", -1)
$Text.value = "First"
$Text.bold = true
// We can now use the values for the controls using $dialog_box.controls
$Search = $dialog_box.controls["Search"]
https://getonetastic.com/docs/OnetasticMacroDocumentation 12/156
11/11/24, 2:09 PM Onetastic Macro Documentation
This is part of the Search & Replace macro and it will display the following dialog box:
Here the DialogBox_Create function creates a new dialog box object. Then we add some controls to it. Text
boxes, drop down controls and check boxes can be added. Finally DialogBox_Show function displays the dialog
box.
Displaying messages
If you wish to only display a message, you can use ShowMessage function:
https://getonetastic.com/docs/OnetasticMacroDocumentation 13/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Task dialogs
If you want user to pick form a few actions and no other input is required, a task dialog may be a suitable option.
https://getonetastic.com/docs/OnetasticMacroDocumentation 14/156
11/11/24, 2:09 PM Onetastic Macro Documentation
// We can now use the values for the controls using $dialog_box.controls
$Search = $dialog_box.controls["Search"]
$Replace = $dialog_box.controls["Replace"]
$Scope = $dialog_box.controls["Scope"]
$MatchCase = $dialog_box.controls["MatchCase"]
// Now store these values so that we can read them back in a subsequent run
LocalStore_Write("LastSearch", $Search)
LocalStore_Write("LastReplace", $Replace)
LocalStore_Write("LastScope", $Scope)
LocalStore_Write("LastMatchCase", $MatchCase)
https://getonetastic.com/docs/OnetasticMacroDocumentation 15/156
11/11/24, 2:09 PM Onetastic Macro Documentation
This macro will create a second image on the same page and copy the existing image data to it, creating a copy of
the image.
Binary Store
In order to create new images or embedded files, the data property must be set to a valid binary data. While
macros can copy such data from existing content, as seen above, they can also store such data and use it to
create new content. Binary store is where macros can store files to be used to create images and embedded files.
To access binary store for a macro you can go to Storage > Edit Binary Storage on the menu. This will display the
Binary Store window:
You can use Add Files button to choose one or more files to add to the binary store. After adding files, you can
rename them or remove any files you don't need:
https://getonetastic.com/docs/OnetasticMacroDocumentation 16/156
11/11/24, 2:09 PM Onetastic Macro Documentation
$page = GetCurrentPage()
This will create a new image using the flower.png file in the binary store. Binary store is per macro. You cannot
access files from binary store of one macro from another macro. If you need to use the same files, simply add
them to each macro.
Sorting objects
Macros can sort a set of objects by any property or value. This is done throught the SortObjects function. A
simple sort macro looks like this:
This macro will sort every paragraph in the current page alphabetically (property "text" was provided in the
second parameter) in ascending order (true was provided in the last parameter).
You can also define custom sort orders by making use of arrays. Below macro will sort each paragraph by the
second letter that appears in the paragraph:
For the custom sorting, the second parameter to SortObjects must be an array that has indices 0 to number of
elements being sorted. Each corresponding value in the array will then be compared to determine the order.
Macro menus
Each macro adds a button to the ribbon to run the macro. Optionally, macros can display a menu in the ribbon
for more options. For example, Function macro displays the following menu:
Macro menus can be static or dynamically generated based on user's usage patterns. For instance a macro like
Search and Replace may display the recently used search and replace terms in the menu.
Setup function
https://getonetastic.com/docs/OnetasticMacroDocumentation 18/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Both static and dynamic menus are created by the Setup function. Setup function is a user defined function in a
macro which will get called whenever Onetastic needs to get a macro's menu to be displayed in the ribbon. Below
is a sample Setup function:
Setup function always has a single parameter byref $menu. This parameter is an object of type MacroMenu . You
can then use the MacroMenu_AddItem function to add menu items. A macro with this Setup function will have the
following menu:
Each menu item is associated with an argument that will be passed to Main function when user clicks on that
menu item. In this case if user clicks the first menu item, Main function for this macro will be called with the
argument "arg1".
Performance Considerations
Setup function will get called every time Onetastic needs to refresh the menu for each macro. This can be after a
macro execution, after a macro is edited, or after a new macro is downloaded. To avoid performance problems,
Setup function should do minimal work and should not be running for a long time. Setup function for a macro will
get aborted if it runs long and the menu for that macro will not be visible. Setup function also cannot access
OneNote content or show dialog boxes.
https://getonetastic.com/docs/OnetasticMacroDocumentation 19/156
11/11/24, 2:09 PM Onetastic Macro Documentation
This will create a sample Setup function which you can use to quickly edit. If a Setup function already exists, this
will switch to it.
This menu will display each menu item and clicking on one of them will start the debugger with the associated
argument passed to the Main function.
isPartOfList (read-only)
isPartOfBulletedList
isPartOfNumberedList
You can set isPartOfBulletedList or isPartOfNumberedList property to true to create a bulleted or numbered
paragraph. Setting them to false will remove the bullet or number.
https://getonetastic.com/docs/OnetasticMacroDocumentation 20/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Bullet Types
Paragraph objects that are part of a bulleted list have the bulletType property indicating what type of bullet they
are displaying. Valid bullet type values are given below:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
https://getonetastic.com/docs/OnetasticMacroDocumentation 21/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Number Sequences
Paragraph objects that are part of a numbered list have the numberSequence property indicating what type of
number sequence they are displaying. Valid number sequence values are given below:
Japanese (Expand)
Chinese (Expand)
Korean (Expand)
Hebrew (Expand)
Arabic (Expand)
Hindi (Expand)
Thai (Expand)
Vietnamese (Expand)
Russian (Expand)
Greek (Expand)
Number Format
In addition to the different number sequences you can get by setting the numberSequence property, you can
also customize numbered lists by setting a format through the numberFormat property. This property is a string
that contains "##" for the number sequence and any other characters to be displayed in the numbered list. The
default value for numberFormat property is "##.". Below are some examples:
Sample Macros
You can find sample Macros in Macroland, specifically created to teach Macro concepts. They are under Samples
category. More samples will be added in the future, so don't forget to check it out frequently.
https://getonetastic.com/docs/OnetasticMacroDocumentation 22/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Concepts
Expressions
Objects
Properties
Variables
Data Types
Arrays
Functions
Literals
Operators
Comments
Expressions
Macro statements mostly evaluate expression to read or modify data. Expressions can be used to assign
variables, access object properties, call functions and do arithmetic, logical or comparison operations. They can
also provide literal values.
// Variables
$name
$format
// Assignment
$i = 0
$i += 1
$x = true
$x &&= false
$s = "text"
$s &= " more text"
// Arithmetic
3 - (5 * 2)
$x || $y
// String concatenation
"text" & $str & " more text"
https://getonetastic.com/docs/OnetasticMacroDocumentation 23/156
11/11/24, 2:09 PM Onetastic Macro Documentation
// Comparison
7 > 4
"text" != $x
// Ternary operator ?:
($x > 3) ? "yes" : "no"
// Function Calls
String_Split($str, ";")
DialogBox_Create("message")
// Property access
GetCurrentPage().name
$Section.color
// Array index
$names[0]
$multi_dim_arr[0][1][2]
$Section.pages[1]
Objects
Objects in macros represent OneNote's notebook/section/page hierarchy as well as the contents of a OneNote
page.
Querying Objects
Macros can query objects using QueryObjects function and modify their properties:
Macros can also create new pages and insert content on a page:
https://getonetastic.com/docs/OnetasticMacroDocumentation 24/156
11/11/24, 2:09 PM Onetastic Macro Documentation
// Create a page at the end of the first section of the current notebook
$Page = InsertObject(GetCurrentNotebook().sections[0], "Page", -1)
Following is the list of objects macros recognize with the hierarchical structure:
Hierarchy Objects
Notebook
│
├─ Section
│ │
│ └─ Page
│
└─ SectionGroup
│
└─ ·····
│
└─ SectionGroup
│
└─ Section
│
└─ Page
Page Objects
Page
│
├─ Image
│ │
│ └─ Tag
│
├─ EmbeddedFile
│ │
https://getonetastic.com/docs/OnetasticMacroDocumentation 25/156
11/11/24, 2:09 PM Onetastic Macro Documentation
│ │
│ └─ Tag
│
├─ Title
│ │
│ └─ Paragraph
│ │
│ ├─ Tag
│ │
│ └─ Text
│
└─ Outline
│
└─ Paragraph
│
├─ Tag
│
├─ Text
│
├─ Image
│
├─ EmbeddedFile
│
└─ Table
│
├─ Column
│
└─ Row
│
└─ Cell
│
└─ Paragraph
│
├─ Tag
│
├─ Text
│
├─ Image
│
├─ EmbeddedFile
│
└─ Table
│
└─ ·····
Properties
Each object in macros have a set of properties. Some of these properties are read-only while most others are
read/write. There are cases where some property may be write-only. For instance formatting properties like bold,
italic etc. on Paragraph s are write-only as they can be set but cannot be determined since a paragraph can
contain text with mixed formatting.
https://getonetastic.com/docs/OnetasticMacroDocumentation 26/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Properties are accessed with the property access operator (.) and they can be used to filter queries if you are
looking for objects with certain property values (e.g. looking for a section with a given color):
They can also be used to sort objects (e.g. sorting pages by date):
You can find the list of properties for each object in object documentation.
Variables
Variables in macros are similar to the concept of variables in any other programming language. They can be used
to temporarily store data by creating and subsequently initializing them with assignment operators. Their values
can then be further manipulated or used in expressions:
$width = 5
$height = 7
$area = $width * $height
Objects themselves and the values of their properties can be stored into variables and after being manipulated
they can be stored back into properties:
// Now show the dialog box, the user choices are stored in $Search,
https://getonetastic.com/docs/OnetasticMacroDocumentation 27/156
11/11/24, 2:09 PM Onetastic Macro Documentation
// $Replace, $Scope and $MatchCase variables after this call
DialogBox_Show($dialog_box)
Data Types
Variables in macros aren't strongly typed. Therefore they can change from one type to the other. For instance a
value of "0" can be string type but modifying it by adding "1" will turn it into numeric type. However a variable
always have a deterministic data type at any given point of macro execution. See Data Types for all the data types
and possible values.
Data Types
Following is the list of data types in macros. Properties can be of one of these data types and variables can be of
one of the base types.
Base Types
Name Possible Values
Numeric Any positive or negative integral or floating point value or zero (0)
Date/Time Type of date/time related properties (e.g. createdTime, lastModifiedTime) in several objects. If
converted to a string or used in a string context (as a parameter to String functions) it has the
following format: YYYY-MM-DDTHH:MM:SS.000Z as specified here. Date/Time functions can be used
to easily retrieve parts of this and convert them to user readable strings.
TimeSpan Represents a span of time. TimeSpan values can be created by TimeSpan function and can be
used to add or subtract from Date/Time values using DateTime_Add and DateTime_Subtract
functions.
Color Type of the color properties (e.g. fontColor, highlightColor) in several objects. Colors are stored in
the canonical #rrggbb format or as automatic if no color was set (e.g. no highlightColor or the
default fontColor). Color names like: black, blue, red, yellow etc. or the value automatic can be
used to set or compare variables or properties of type Color. The function Color can be used to
create variables of type Color. See also the possible values for color names at Color
Binary Binary data for an Image or an EmbeddedFile . Binary data can be obtained from binary store to
create Image or EmbeddedFile objects. See Using binary data for more information.
https://getonetastic.com/docs/OnetasticMacroDocumentation 28/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Description
Type of the selection property in several objects. For objects that aren't selected, it will have a value of
none, while for selected objects it will have a value of all or partial depending on how much of it is
selected. For instance a partially selected paragraph will have a value of partial.
Possible Values
none, partial, all
SuperSub
Description
Type of the supersub property in Text and Paragraph objects. If the text is formatted as a superscript or
subscript, then it will have a value of super or sub value, otherwise it will have a value of none.
Possible Values
none, super, sub
ContentType
Description
Type of the contentType property in Paragraph objects.
Possible Values
image, table, text, ink drawing, ink writing, embedded file, embedded media, unknown
ImageFormat
Description
Type of the format property in Image objects.
Possible Values
png, jpg, emf
Alignment
Description
Type of the alignment property in Paragraph objects.
Possible Values
left, center, right
Orientation
https://getonetastic.com/docs/OnetasticMacroDocumentation 29/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Description
Type of the orientation property in Page objects.
Possible Values
portrait, landscape
ObjectType
Description
Type of a OneNote object.
Possible Values
NotebookRoot, Notebook, SectionGroup, Section, Page, Title, Outline, Table, Column, Row, Cell,
Paragraph, Text, Image, EmbeddedFile
ParagraphStyle
Description
Type of the style property in Paragraph objects.
Possible Values
p, h1, h2, h3, h4, h5, h6, PageTitle, cite, blockquote, code
DateTimePickerType
Description
Type of a Date/Time picker control in a DialogBox .
Possible Values
date, time, datetime
Arrays
Variables can store a single value or a set of values. Variables that store a set of values are of Array data type.
Arrays can store an unbounded amount of <key, value> pairs. The values are always accessed by providing the
key (known as index). New elements can be added to arrays by assignment and specifying the a key that doesn't
exist in the array:
Creating Arrays
$Names[0] = "Fred"
$Names[1] = "Kate"
$Names[2] = "Sally"
Arrays can also be created by Array function by simply providing the list of elements:
https://getonetastic.com/docs/OnetasticMacroDocumentation 30/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Array keys are of string or numeric types and they don't have to follow any order.
Array functions
There are a several functions that generate and consume arrays. QueryObjects and QueryText functions return
arrays of objects. String_Split function splits a given string into an array of strings, while Array_Join function
reverses this. Array_Length function will return the number of elements in an array.
Multi-dimensional Arrays
Arrays can be multi-dimensional if they contain other arrays:
Functions
Functions in macros are similar to the same concept in other programming languages. They take one or more
parameters and return a single value (or no value). They can be used to retrieve objects, manipulate strings,
dates, arrays, create and display dialog boxes and control the macro execution.
Following is an example usage of String_Length and GetCurrentPage functions to obtain the length of the title
of the current page:
$length = String_Length(GetCurrentPage().name)
Array Functions
Color Functions
Data Store Functions
Date/Time Functions
Dialog Box Functions
Macro Execution Functions
Macro Menu Functions
Object Functions
Special Functions
String Functions
Window Functions
Literals
https://getonetastic.com/docs/OnetasticMacroDocumentation 32/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Literals values can be used in the expressions to provide a fixed value. Literals can be of type string, numeric or
bool. Following is an example usage of a string literal to modify the title of the current page:
The break statement here is also using the numeric literal "1".
Operators
Macro expressions can contain several different operators. They can be used for assignments, comparisons,
arithmetic or logical operations and string concatenations. Following is a list of all the operators. Operators can
be operating on one (unary), two (binary) or three (ternary) sub expressions:
Arithmetic Operators
+ Addition binary
– Subtraction binary
* Multiplication binary
/ Division binary
% Modulo binary
Increment/Decrement Operators
https://getonetastic.com/docs/OnetasticMacroDocumentation 33/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Assignment Operators
= Assignment binary
Comparison Operators
== Equals binary
Logical Operators
|| Logical Or binary
https://getonetastic.com/docs/OnetasticMacroDocumentation 34/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Ternary Operator
Operator Precedence
In macro expressions, following operator precedence rules apply. The order of operations can be changed by
providing parantheses.
1 Increment/Decrement ++ ––
2 Unary ! – +
3 Product * / %
7 Logical Or ||
8 Ternary ?:
Comments
You can provide comments between macro statements to improve readability of your macros. Comments are
inserted using Comment statements :
https://getonetastic.com/docs/OnetasticMacroDocumentation 35/156
11/11/24, 2:09 PM Onetastic Macro Documentation
DialogBox_AddDropDown($dialog_box, "&Scope", $Scope, "Current section", $Options)
DialogBox_AddCheckBox($dialog_box, "Match &case", $MatchCase, false)
This helps with visually separating statements. Comments can also be used to temporarily remove statements
from macro execution adding // in front of them (commenting-out):
Statements
for
foreach
if
else if
else
switch
case
default
while
expression
comment
break
continue
return
https://getonetastic.com/docs/OnetasticMacroDocumentation 36/156
11/11/24, 2:09 PM Onetastic Macro Documentation
for Statement
Description
Executes an initialization expression followed by a set of statements until the given boolean expression evaluates
false. Evaluates the increment expression after each iteration. You can break out of a for loop using a break
Syntax
Examples
$sum = 0
// $sum is now 10 (1 + 2 + 3 + 4)
foreach Statement
Description
Iterates over a given array, stores each element in the array in the given variable and executes a set of statements
for each iteration. You can break out of a foreach loop using a break statement or skip to the next iteration
using a continue statement.
Syntax
Examples
$array = Array(3, 5, 7, 9)
$sum = 0
// $sum is now 24 (3 + 5 + 7 + 9)
https://getonetastic.com/docs/OnetasticMacroDocumentation 37/156
11/11/24, 2:09 PM Onetastic Macro Documentation
if Statement
Description
Executes a set of statements if the given boolean expression evaluates true.
Syntax
if (boolean-expression)
Statements...
Examples
if ($x == 0)
// Handle when $x is 0
else if ($x < 0)
// Handle when $x is negative
else
// Handle when $x is positive
else if Statement
Description
Executes a set of statements if the boolean expression of a preceeding if or else if statement evaluates false
and the given boolean expression evaluates true.
Syntax
else if (boolean-expression)
Statements...
Examples
if ($x == 0)
// Handle when $x is 0
else if ($x < 0)
// Handle when $x is negative
else
// Handle when $x is positive
else Statement
https://getonetastic.com/docs/OnetasticMacroDocumentation 38/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Description
Executes a set of statements if the boolean expression of an if statement evaluates false.
Syntax
else
Statements...
Examples
if ($x == 0)
// Handle when $x is 0
else if ($x < 0)
// Handle when $x is negative
else
// Handle when $x is positive
switch Statement
Description
Evaluates an expression and compares it to the value in each of the subsequent case statements to execute a
different set of statements based on which value it equals to.
Syntax
switch (expression)
Statements...
Examples
switch ($x)
case 0:
// Handle when $x is 0
// Make sure to have a break at the end of a case
// or it will fall through to the next case
// See handling of cases 1-3 below as an example
break
case 1:
case 2:
case 3:
// Handle when $x is 1, 2, or 3
break
case 4:
https://getonetastic.com/docs/OnetasticMacroDocumentation 39/156
11/11/24, 2:09 PM Onetastic Macro Documentation
// Handle when $x is 4
break
default:
// Handle all other cases
case Statement
Description
Compares the given value to the value of the parent switch statement and executes a set of statements if they
are equal. If a break statement is not found inside a case statement, then execution continues into the next
case or default statement, if any exists.
Syntax
case expression:
Statements...
Examples
switch ($x)
case 0:
// Handle when $x is 0
// Make sure to have a break at the end of a case
// or it will fall through to the next case
// See handling of cases 1-3 below as an example
break
case 1:
case 2:
case 3:
// Handle when $x is 1, 2, or 3
break
case 4:
// Handle when $x is 4
break
default:
// Handle all other cases
default Statement
https://getonetastic.com/docs/OnetasticMacroDocumentation 40/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Description
Executes a set of statements if values of none of the case statements are equal to the value of the parent
switch statement. If a break statement is not found inside a default statement, then execution continues into
the next case statement, if any exists.
Syntax
default:
Statements...
Examples
switch ($x)
case 0:
// Handle when $x is 0
// Make sure to have a break at the end of a case
// or it will fall through to the next case
// See handling of cases 1-3 below as an example
break
case 1:
case 2:
case 3:
// Handle when $x is 1, 2, or 3
break
case 4:
// Handle when $x is 4
break
default:
// Handle all other cases
while Statement
Description
Executes a set of statements as long as the given boolean expression evaluates true. You can break out of a
while loop using a break statement or skip to the next iteration using a continue statement.
Syntax
while (boolean-expression)
Statements...
https://getonetastic.com/docs/OnetasticMacroDocumentation 41/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Examples
$sum = 0
$i = 1
// $sum is now 10 (1 + 2 + 3 + 4)
Expression Statement
Description
Evaluates an expression.
Syntax
expression
Examples
// Variables
$name
$format
// Assignment
$i = 0
$i += 1
$x = true
$x &&= false
$s = "text"
$s &= " more text"
// Arithmetic
3 - (5 * 2)
$x || $y
// String concatenation
"text" & $str & " more text"
https://getonetastic.com/docs/OnetasticMacroDocumentation 42/156
11/11/24, 2:09 PM Onetastic Macro Documentation
// Comparison
7 > 4
"text" != $x
// Ternary operator ?:
($x > 3) ? "yes" : "no"
// Function Calls
String_Split($str, ";")
DialogBox_Create("message")
// Property access
GetCurrentPage().name
$Section.color
// Array index
$names[0]
$multi_dim_arr[0][1][2]
$Section.pages[1]
Comment Statement
Description
Used to provide textual explanations (comments) within the source code or temporarily removing a set of
statements from the macro execution (comment-out).
Syntax
// comment
break Statement
https://getonetastic.com/docs/OnetasticMacroDocumentation 43/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Description
Breaks out of a for , foreach or a while loop. With the given numeric-expression, it can break out of multiple
levels of loops. The expression is optional.
Syntax
break numeric-expression
Examples
$sum = 0
$sum += $i
// Stop after 7
if ($i == 7)
break
// $sum is now 25 (3 + 4 + 5 + 6 + 7)
continue Statement
Description
Skips to the next iteration of a for , foreach or a while loop without executing the remaining statements in the
loop. With the given numeric-expression, it can skip iterations of multiple levels of loops. The expression is
optional.
Syntax
continue numeric-expression
Examples
$sum = 0
https://getonetastic.com/docs/OnetasticMacroDocumentation 44/156
11/11/24, 2:09 PM Onetastic Macro Documentation
$sum += $i
// Stop after 7
if ($i == 7)
break
// $sum is now 25 (3 + 4 + 5 + 6 + 7)
return Statement
Description
Returns the given expression from the current function. If the current function is Main, exists the macro. The
expression is optional.
Syntax
return expression
Examples
function PageHasImages($page)
// Function takes a page returns whether it found any images or not
$images = QueryObjects("Image", $page)
return Array_Length($images) > 0
Hierarchy Objects
NotebookRoot
Notebook
SectionGroup
Section
Page
NotebookRoot Object
Description
https://getonetastic.com/docs/OnetasticMacroDocumentation 45/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Represents root of all notebooks in OneNote. The current NotebookRoot can be obtained by calling
GetNotebookRoot function.
Hierarchical Structure
NotebookRoot objects can contain following objects: Notebook
Properties
Name Type Access Description
type ObjectType read-only Type of this object. Always has the value of "NotebookRoot".
Notebook Object
Description
Represents a notebook in OneNote. The current Notebook can be obtained by calling GetCurrentNotebook
function.
Hierarchical Structure
Notebook objects can contain following objects: SectionGroup Section
Properties
Name Type Access Description
https://getonetastic.com/docs/OnetasticMacroDocumentation 46/156
11/11/24, 2:09 PM Onetastic Macro Documentation
lastModifiedTime DateTime read-write The date and time of the last modification to this
Notebook .
sectionGroups Array<SectionGroup> read-only The list of section groups directly in this Notebook .
type ObjectType read-only Type of this object. Always has the value of
"Notebook".
SectionGroup Object
Description
Represents a section group in OneNote. The current SectionGroup can be obtained by calling
GetCurrentSectionGroup function.
Hierarchical Structure
SectionGroup objects can be found under following objects: Notebook SectionGroup
Properties
Name Type Access Description
isRecycleBin Bool read-only Whether this SectionGroup is the recycle bin for
the notebook.
lastModifiedTime DateTime read-write The date and time of the last modification to this
SectionGroup .
type ObjectType read-only Type of this object. Always has the value of
"SectionGroup".
Section Object
Description
Represents a section in OneNote. The current Section can be obtained by calling GetCurrentSection function.
Hierarchical Structure
Section objects can be found under following objects: Notebook SectionGroup
Properties
Name Type Access Description
areAllPagesAvailable Bool read-only Whether all pages in this Section is available or not. Pages
may not be available if they weren't fully uploaded by the
client that created it.
https://getonetastic.com/docs/OnetasticMacroDocumentation 48/156
11/11/24, 2:09 PM Onetastic Macro Documentation
isCurrentlyViewed Bool read-only Whether this Section is currently being viewed by the user
in OneNote or not.
isDeletedPages Bool read-only Whether this Section is the recycle bin section that
contains the deleted pages for the notebook.
isInRecycleBin Bool read-only Whether this Section is in the notebook recycle bin or not.
Filter by this property if you want to exclude Section s in
recycle bin.
lastModifiedTime DateTime read-write The date and time of the last modification to this Section .
type ObjectType read-only Type of this object. Always has the value of "Section".
Page Object
Description
Represents a page in OneNote. The current Page can be obtained by calling GetCurrentPage function.
Hierarchical Structure
Page objects can be found under following objects: Section
Page objects can contain following objects: Image Title Outline EmbeddedFile
https://getonetastic.com/docs/OnetasticMacroDocumentation 49/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Properties
Name Type Access Description
automaticSize Bool read-write Whether this Page has a fixed printed paper
width and height or not.
dateTime DateTime read-write The date and time this Page is originally
created.
images Array<Image> read-only The list of images directly under in this Page .
This array doesn't contain images in outlines.
lastModifiedTime DateTime read-write The date and time of the last modification to
this Page .
marginBottom Numeric read-write The printed paper bottom margin for this
Page .
marginLeft Numeric read-write The printed paper left margin for this Page .
marginRight Numeric read-write The printed paper right margin for this Page .
marginTop Numeric read-write The printed paper top margin for this Page .
https://getonetastic.com/docs/OnetasticMacroDocumentation 50/156
11/11/24, 2:09 PM Onetastic Macro Documentation
pageLevel Numeric read-write The subpage level of this Page . Subpages will
have a level of 2 or 3 where main pages will
have a level of 1.
pageObjects Array<PageObject> read-only The list of page object directly under this
Page .
ruleLinesHorizontalColor Color read-write The color for the horizontal rule lines for this
Page .
ruleLinesMarginColor Color read-write The color for the vertical margin rule line for
this Page .
ruleLinesVerticalColor Color read-write The color for the vertical rule lines for this
Page .
ruleLinesVerticalSpacing Numeric read-write The amount of space between the vertical rule
lines for this Page in points.
ruleLinesVisible Bool read-write Whether the rule lines for this Page is visible
or not.
stationeryName String read-only The name of the page template used to create
this Page .
title Title read-only The title area of the page that contains the
title bar, date and time. Accessing this object
will create the page title if it doesn't already
exist. Use hasTitle property to check whether
a title already exists or not.
https://getonetastic.com/docs/OnetasticMacroDocumentation 51/156
11/11/24, 2:09 PM Onetastic Macro Documentation
type ObjectType read-only Type of this object. Always has the value of
"Page".
Page Objects
Title
Outline
Table
Column
Row
Cell
Paragraph
Text
Image
EmbeddedFile
Tag
Title Object
Description
Represents the title in a OneNote page.
Hierarchical Structure
Title objects can be found under following objects: Page
Remarks
A Page created via Onetastic macro will come with a title if the default template of the Section it is created
under has one.
Properties
Name Type Access Description
https://getonetastic.com/docs/OnetasticMacroDocumentation 52/156
11/11/24, 2:09 PM Onetastic Macro Documentation
selection Selection read-write Whether this Title is fully or partially selected or not.
showDate Bool read-write Whether the page creation date is displayed under this Title or not.
showTime Bool read-write Whether the page creation time is displayed under this Title or not.
type ObjectType read-only Type of this object. Always has the value of "Title".
Outline Object
Description
Represents a note container (outline) in a OneNote page.
Hierarchical Structure
Outline objects can be found under following objects: Page
Properties
Name Type Access Description
authorInitials String read-write The initials of the original author of this Outline .
creationTime DateTime read-write The date and time this Outline is originally created.
lastModifiedBy String read-write The person who last modified this Outline .
lastModifiedByInitials String read-write The initials of the person who last modified this
Outline .
lastModifiedTime DateTime read-write The date and time of last modification on this
Outline .
https://getonetastic.com/docs/OnetasticMacroDocumentation 53/156
11/11/24, 2:09 PM Onetastic Macro Documentation
type ObjectType read-only Type of this object. Always has the value of "Outline".
Table Object
Description
Represents a table in a OneNote page.
Hierarchical Structure
Table objects can be found under following objects: Paragraph
Properties
Name Type Access Description
authorInitials String read-write The initials of the original author of this Table .
bordersVisible Bool read-write Whether the borders of this Table is visible or not.
https://getonetastic.com/docs/OnetasticMacroDocumentation 54/156
11/11/24, 2:09 PM Onetastic Macro Documentation
creationTime DateTime read-write The date and time this Table is originally created.
lastModifiedBy String read-write The person who last modified this Table .
lastModifiedByInitials String read-write The initials of the person who last modified this Table .
lastModifiedTime DateTime read-write The date and time of the last modification to this Table
selection Selection read-write Whether this Table is fully or partially selected or not.
type ObjectType read-only Type of this object. Always has the value of "Table".
Column Object
Description
Represents a column of a Table in a OneNote page.
Hierarchical Structure
Column objects can be found under following objects: Table
Remarks
To insert Column s into a Table , insert one or more Cell object under Row object.
Properties
Name Type Access Description
isLocked Bool read-write Whether the width of this Column was set by the user or not.
type ObjectType read-only Type of this object. Always has the value of "Column".
https://getonetastic.com/docs/OnetasticMacroDocumentation 55/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Row Object
Description
Represents a row of a Table in a OneNote page.
Hierarchical Structure
Row objects can be found under following objects: Table
Properties
Name Type Access Description
authorInitials String read-write The initials of the original author of this Row .
creationTime DateTime read-write The date and time this Row is originally created.
lastModifiedBy String read-write The person who last modified this Row .
lastModifiedByInitials String read-write The initials of the person who last modified this Row .
lastModifiedTime DateTime read-write The date and time of the last modification to this Row .
selection Selection read-write Whether this Row is fully or partially selected or not.
type ObjectType read-only Type of this object. Always has the value of "Row".
Cell Object
Description
Represents a cell of a table in a OneNote page.
Hierarchical Structure
Cell objects can be found under following objects: Row
Remarks
Insert Table object under Cell object to create nested tables. Insert Paragraph object under Cell object to
add text into the cell.
Properties
Name Type Access Description
authorInitials String read-write The initials of the original author of this Cell .
backgroundColor Color read-write The background color for this Cell . This property
requires OneNote 2013 or above.
colIndex Numeric read-only The number of Column s before the column this
Cell is in.
creationTime DateTime read-write The date and time this Cell is originally created.
lastModifiedBy String read-write The person who last modified this Cell .
lastModifiedByInitials String read-write The initials of the person who last modified this Cell
lastModifiedTime DateTime read-write The date and time of the last modification to this
Cell .
rowIndex Numeric read-only The number of Row s before the row this Cell is in.
selection Selection read-write Whether this Cell is fully or partially selected or not.
type ObjectType read-only Type of this object. Always has the value of "Cell".
Paragraph Object
Description
Represents a paragraph of text in a OneNote page.
https://getonetastic.com/docs/OnetasticMacroDocumentation 57/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Hierarchical Structure
Paragraph objects can be found under following objects: Outline Cell Title
Paragraph objects can contain following objects: Text Image Table EmbeddedFile Tag
Remarks
Paragraphs can be part of bulleted or numbered list. See Bulleted and numbered lists for more information
Properties
Name Type Access Description
alignment Alignment read-write Text alignment for this Paragraph (e.g. left, right or
center).
authorInitials String read-write The initials of the original author of this Paragraph .
bold Bool write-only Whether the text in this Paragraph is bold or not. This
property is write-only as there may be text with
different formatting in the paragraph. Setting this
property will apply its value to the whole paragraph.
bulletFontColor Color read-write The color for the bullet for this Paragraph .
bulletFontSize Numeric read-write The font size for the bullet for this Paragraph .
bulletType Numeric read-write The type of the bullet for this Paragraph . See Bulleted
and numbered lists for more information.
content Mixed read-only The content stored in this Paragraph . To find out what
type of object is stored in this property, check the
contentType property:
contentType content
text Array<Text>
table Table
image Image
creationTime DateTime read-write The date and time this Paragraph is originally created.
fontColor Color write-only The text color for this Paragraph . This property is
write-only as there may be text with different
formatting in the paragraph. Setting this property will
apply its value to the whole paragraph.
fontName String write-only The name of the font for this Paragraph . This property
is write-only as there may be text with different
formatting in the paragraph. Setting this property will
apply its value to the whole paragraph.
fontSize Numeric write-only The font size for this Paragraph . This property is write-
only as there may be text with different formatting in
the paragraph. Setting this property will apply its value
to the whole paragraph.
highlightColor Color write-only The highlight color for this Paragraph . This property is
write-only as there may be text with different
formatting in the paragraph. Setting this property will
apply its value to the whole paragraph.
indent Numeric read-write The indent amount for this Paragraph , relative to its
parent Outline or Cell . An unindented Paragraph
has an indent of 0.
isPartOfBulletedList Bool read-write Whether this Paragraph is part of a bulleted list or not.
See Bulleted and numbered lists for more information.
https://getonetastic.com/docs/OnetasticMacroDocumentation 59/156
11/11/24, 2:09 PM Onetastic Macro Documentation
italic Bool write-only Whether the text in this Paragraph is italicized or not.
This property is write-only as there may be text with
different formatting in the paragraph. Setting this
property will apply its value to the whole paragraph.
lang String write-only The language the text in this Paragraph is writte in.
This property is write-only as there may be text with
different languages in the paragraph. Setting this
property will apply its value to the whole paragraph.
lastModifiedBy String read-write The person who last modified this Paragraph .
lastModifiedByInitials String read-write The initials of the person who last modified this
Paragraph .
lastModifiedTime DateTime read-write The date and time of the last modification to this
Paragraph .
listAlignment Alignment read-write The text alignment for the numbered list for this
Paragraph (left vs right). The default alignment value is
"right".
listSpacing Numeric read-write The space between the numbered list and the
paragraph in points. The default spacing amount is 7.2
points (0.1 inches).
numberBold Bool read-write Whether the numbered list for this Paragraph is bold
or not.
numberFont String read-write The name of the font face for the numbered list for this
Paragraph .
numberFontColor Color read-write The color for the numbered list for this Paragraph .
numberFontSize Numeric read-write The size of the font for the numbered list for this
Paragraph .
numberFormat String read-write The number format for the numbered list for this
Paragraph . See Bulleted and numbered lists for more
information.
https://getonetastic.com/docs/OnetasticMacroDocumentation 60/156
11/11/24, 2:09 PM Onetastic Macro Documentation
numberItalic Bool read-write Whether the numbered list for this Paragraph is
italicized or not.
numberLanguage String read-write The language for the numbered list for this Paragraph .
numberSequence Numeric read-write The number sequence for the numbered list for this
Paragraph . See Bulleted and numbered lists for more
information.
numberText String read-only The text for the numbered list for this Paragraph .
spaceAfter Numeric read-write The amount of space after this Paragraph in points.
This property requires OneNote 2013 or above.
spaceBefore Numeric read-write The amount of space before this Paragraph in points.
This property requires OneNote 2013 or above.
spaceBetween Numeric read-write The amount of space between the lines of this
Paragraph in points. This property requires OneNote
2013 or above.
strikethrough Bool write-only Whether the text in this Paragraph is striked through
or not. This property is write-only as there may be text
with different formatting in the paragraph. Setting this
property will apply its value to the whole paragraph.
https://getonetastic.com/docs/OnetasticMacroDocumentation 61/156
11/11/24, 2:09 PM Onetastic Macro Documentation
type ObjectType read-only Type of this object. Always has the value of
"Paragraph".
tagCompleted Bool read-write Whether the first tag associated with this Paragraph is
completed (checked) or not. This property is deprecated. Use
tags property instead.
tagCompletionDate DateTime read-write The date and time of completion of the first tag associated with
this Paragraph . This property is deprecated. Use tags property
instead.
tagCreationDate DateTime read-write The date and time of creation of the first tag associated with
this Paragraph . This property is deprecated. Use tags property
instead.
tagDisabled Bool read-write Whether the first tag associated with this Paragraph is disabled
(dimmed) or not. This property is deprecated. Use tags property
instead.
tagFontColor Color read-only The font color for the first tag associated with this Paragraph
tagHighlightColor Color read-only The highlight color for the first tag associated with this
Paragraph for tags that use formatting instead of a symbol.
This property is deprecated. Use tags property instead.
tagName String read-only The name of the first tag associated with this Paragraph . This
property is deprecated. Use tags property instead.
tagSymbol Numeric read-only The symbol of the first tag associated with this Paragraph . This
property is deprecated. Use tags property instead.
https://getonetastic.com/docs/OnetasticMacroDocumentation 62/156
11/11/24, 2:09 PM Onetastic Macro Documentation
tagType Numeric read-only The type of the first tag associated with this Paragraph . This
property is deprecated. Use tags property instead.
Text Object
Description
Represents a range of text.
Hierarchical Structure
Text objects can be found under following objects: Paragraph
Properties
Name Type Access Description
endIndex Numeric read-only The number of characters before the end of this Text in the
paragraph.
fontName String read-write Name of the font face for this Text .
hyperlink String read-write The hyperlink of this Text (user would navigate to this hyperlink
when clicking on this Text ).
lang String read-write The language in which this Text is written in.
startIndex Numeric read-only The number of characters before this Text in the containing
paragraph. The first Text will start with index 0 and each character
will be counted as 1.
https://getonetastic.com/docs/OnetasticMacroDocumentation 63/156
11/11/24, 2:09 PM Onetastic Macro Documentation
type ObjectType read-only Type of this object. Always has the value of "Text".
Image Object
Description
Represents an image in a OneNote page.
Hierarchical Structure
Image objects can be found under following objects: Paragraph Page
Properties
Name Type Access Description
altText String read-write Alternative text for this Image . Used if the page is
exported as HTML.
format ImageFormat read-write Encoding format of this Image . See data types for
possible values.
hyperlink String read-write Hyperlink of this Image user would navigate to this
hyperlink when Ctrl+clicking on this Image ).
lastModifiedTime DateTime read-write The date and time of last modification on this
Image .
https://getonetastic.com/docs/OnetasticMacroDocumentation 64/156
11/11/24, 2:09 PM Onetastic Macro Documentation
printOutFileNumber Numeric read-write The file number that points to corresponding the
printout file on the page for this Image . Only valid
for printouts.
printOutPageNumber Numeric read-write The page number that points to corresponding the
printout file on the page for this Image . Only valid
for printouts.
type ObjectType read-only Type of this object. Always has the value of "Image".
z Numeric read-write The z-order of this Image on the page. Objects with
higher z-order will show up in front of objects with
lower z-orders.
Deprecated Properties
Following properties are deprecated. Do not use these in new macros. See descriptions below on what to use
instead.
tagCompleted Bool read-write Whether the first tag associated with this Image is completed
(checked) or not. This property is deprecated. Use tags property
instead.
https://getonetastic.com/docs/OnetasticMacroDocumentation 65/156
11/11/24, 2:09 PM Onetastic Macro Documentation
tagCompletionDate DateTime read-write The date and time of completion of the first tag associated with
this Image . This property is deprecated. Use tags property
instead.
tagCreationDate DateTime read-write The date and time of creation of the first tag associated with
this Image . This property is deprecated. Use tags property
instead.
tagDisabled Bool read-write Whether the first tag associated with this Image is disabled
(dimmed) or not. This property is deprecated. Use tags property
instead.
tagFontColor Color read-only The font color for the first tag associated with this Image for
tags that use formatting instead of a symbol. This property is
deprecated. Use tags property instead.
tagHighlightColor Color read-only The highlight color for the first tag associated with this Image
tagName String read-only The name of the first tag associated with this Image . This
property is deprecated. Use tags property instead.
tagSymbol Numeric read-only The symbol used for the first tag associated with this Image .
This property is deprecated. Use tags property instead.
tagType Numeric read-only The type of the first tag associated with this Image . This
property is deprecated. Use tags property instead.
EmbeddedFile Object
Description
Represents an embedded file attachment in a OneNote page.
Hierarchical Structure
EmbeddedFile objects can be found under following objects: Paragraph Page
Properties
Name Type Access Description
https://getonetastic.com/docs/OnetasticMacroDocumentation 66/156
11/11/24, 2:09 PM Onetastic Macro Documentation
fileName String read-write File name of this EmbeddedFile . This can only be set on newly
inserted embedded files.
lastModifiedTime DateTime read-write The date and time of last modification on this EmbeddedFile .
selection Selection read-write Whether this EmbeddedFile is fully or partially selected or not.
type ObjectType read-only Type of this object. Always has the value of "EmbeddedFile".
y Numeric read-write The vertical position of this EmbeddedFile on the page in points.
z Numeric read-write The z-order of this EmbeddedFile on the page. Objects with
higher z-order will show up in front of objects with lower z-
orders.
Deprecated Properties
Following properties are deprecated. Do not use these in new macros. See descriptions below on what to use
instead.
tagCompleted Bool read-write Whether the first tag associated with this EmbeddedFile is
completed (checked) or not. This property is deprecated. Use
tags property instead.
tagCompletionDate DateTime read-write The date and time of completion of the first tag associated with
this EmbeddedFile . This property is deprecated. Use tags
property instead.
tagCreationDate DateTime read-write The date and time of creation of the first tag associated with
this EmbeddedFile . This property is deprecated. Use tags
property instead.
tagDisabled Bool read-write Whether the first tag associated with this EmbeddedFile is
disabled (dimmed) or not. This property is deprecated. Use tags
https://getonetastic.com/docs/OnetasticMacroDocumentation 67/156
11/11/24, 2:09 PM Onetastic Macro Documentation
property instead.
tagFontColor Color read-only The font color for the first tag associated with this
EmbeddedFile for tags that use formatting instead of a symbol.
This property is deprecated. Use tags property instead.
tagHighlightColor Color read-only The highlight color for the first tag associated with this
EmbeddedFile for tags that use formatting instead of a symbol.
This property is deprecated. Use tags property instead.
tagName String read-only The name of the first tag associated with this EmbeddedFile .
This property is deprecated. Use tags property instead.
tagSymbol Numeric read-only The symbol used for the first tag associated with this
EmbeddedFile . This property is deprecated. Use tags property
instead.
tagType Numeric read-only The type of the first tag associated with this EmbeddedFile . This
property is deprecated. Use tags property instead.
Tag Object
Description
Represents a tag in a OneNote page.
Hierarchical Structure
Tag objects can be found under following objects: Paragraph Image EmbeddedFile
Remarks
Tags can appear on Image s and EmbeddedFile s if they are directly under a Page and on all Paragraph s. For
Image s and EmbeddedFile s that are under Outline s, check for the parent Paragraph with GetParentOfType
function.
Tag Symbols
Following symbols can be used for tags
1 2 3 61 13 40 65 85 44
4 5 6 64 84 43 62 82 41
7 8 9 56 77 36 54 75 34
10 11 12 63 83 39 67 87 46
48 69 28 60 81 42 68 88 47
https://getonetastic.com/docs/OnetasticMacroDocumentation 68/156
11/11/24, 2:09 PM Onetastic Macro Documentation
50 71 30 49 70 29 58 79 38
52 73 32 51 72 31 59 80 16
96 95 94 53 74 33 57 78 37
99 98 97 55 76 35 66 86 45
100 101 102 113 25 26 127 128 27
103 104 105 114 115 116 129 130 131
106 107 108 112 22 23 132 133 134
109 18 110 120 19 20 135 136 137
14 15 17 121 122 123 138 139 140
21 24 111 124 125 126 141 142 143
117 118 119
To change a Tag 's symbol, set its symbol property to the number next to the symbol image above.
Properties
Name Type Access Description
completionDate DateTime read-write The date and time of completion of this Tag .
creationDate DateTime read-write The date and time of creation of this Tag .
fontColor Color read-write The font color for this Tag for tags that use formatting instead of
a symbol.
highlightColor Color read-write The highlight color for this Tag for tags that use formatting
instead of a symbol.
symbol Numeric read-write The symbol for this Tag . See remarks for the symbols.
type ObjectType read-only Type of this object. Always has the value of "Tag".
Other Objects
DialogBox
MacroMenu
Window
DialogBox Object
https://getonetastic.com/docs/OnetasticMacroDocumentation 69/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Description
Represents a dialog box to interact with the user.
Remarks
Represents a dialog box to display a message or request input from user. Dialog boxes can be created with
DialogBox_Create and displayed with DialogBox_Show . Controls can be added to dialog boxes with
DialogBox_AddTextBox , DialogBox_AddLabel , DialogBox_AddCheckBox , DialogBox_AddDropDown ,
DialogBox_AddComboBox , and DialogBox_AddColorPicker functions. Dialog box objects have a member named
"controls" to access the user input after they are displayed.
Properties
Name Type Access Description
controls Array<Mixed> read-only The values provided by the user for the controls on the dialog box after
the dialog is displayed with DialogBox_Show function. The value for
checkboxes are Bool while the values for textboxes and drop down list
boxes are Strings.
type ObjectType read-only Type of this object. Always has the value of "DialogBox".
MacroMenu Object
Description
Represents the menu of a macro in the ribbon.
Remarks
MacroMenu object represents the menu of the current macro to be displayed in the ribbon. This object is passed
as an argument to the Setup function to create a menu. Menu items can be added to a menu using the
MacroMenu_AddItem function. See Macro menus for more information on menus.
Properties
Name Type Access Description
type ObjectType read-only Type of this object. Always has the value of "MacroMenu".
Window Object
Description
Represents a OneNote window.
https://getonetastic.com/docs/OnetasticMacroDocumentation 70/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Remarks
OneNote can display notebooks in one or more Windows. The collection of these windows can be accessed
through GetWindows function. At most one of the windows is the current window. This can be checked by
isCurrent property and the current window can be accessed through Window_GetCurrent . A window can be made
current via Window_SetCurrent function. New windows can be created by Window_Create and windows can be
closed by Window_Close . The page a window is displaying can be changed by Window_NavigateTo .
Properties
Name Type Access Description
isCurrent Bool read-only Whether this window is the current window or not.
notebook Notebook read-only The notebook this window is currently displaying. This property
may be empty if the window is not currently displaying a
notebook.
page Page read-only The page this window is currently displaying. This property may be
empty if the window is not currently displaying a page.
section Section read-only The section this window is currently displaying. This property may
be empty if the window is not currently displaying a section.
sectionGroup SectionGroup read-only The section group this window is currently displaying. This
property may be empty if the window is not currently displaying a
section group.
type ObjectType read-only Type of this object. Always has the value of "Window".
Functions
Array Functions
Color Functions
Data Store Functions
Date/Time Functions
Dialog Box Functions
Macro Execution Functions
Macro Menu Functions
Object Functions
Special Functions
String Functions
https://getonetastic.com/docs/OnetasticMacroDocumentation 71/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Window Functions
Array Functions
Array
Array_FlipKeysAndValues
Array_FromKeysAndValues
Array_FromRange
Array_Join
Array_KeyExists
Array_Keys
Array_Length
Array_Merge
Array_PopBack
Array_PopFront
Array_PushBack
Array_PushFront
Array_RemoveByKey
Array_Reverse
Array_Shuffle
Array_Slice
Array_SortByKey
Array_SortByValue
Array_Splice
Array_Unique
Array_ValueExists
Array_Values
IsArray
Array
Creates an array with given arguments.
Syntax
https://getonetastic.com/docs/OnetasticMacroDocumentation 72/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Parameters
// Empty Array
$array = Array()
// 2 dimensional array
$array = Array(Array(0, 1, 2), Array(3, 4, 5), Array(5, 6, 7))
// This will be 5:
$element = $array[1][2]
Array_FlipKeysAndValues
Exchanges the keys and their associated values in the given array. The values must be numeric or string since
they will now become keys.
Syntax
Parameters
Array array
Array to flip keys and values.
Examples
Array_FlipKeysAndValues($array)
// Now we have the following keys and values:
https://getonetastic.com/docs/OnetasticMacroDocumentation 73/156
11/11/24, 2:09 PM Onetastic Macro Documentation
// "red" => 0
// "green" => 1
// "blue" => 2
// 5 => 3
// If the values aren't unique, latter values will write over former ones
$array = Array(3, 5, 8, 5, 2, 3)
// This created the following array
// 0 => 3, 1 => 5, 2 => 8, 3 => 5, 4 => 2, 5 => 3
Array_FlipKeysAndValues($array)
// Now we have the following keys and values:
// 3 => 5, 5 => 3, 8 => 2, 2 => 4
Array_FromKeysAndValues
Creates an array by using one array for keys and another for its values. The given arrays must have the same size.
Syntax
Array Array_FromKeysAndValues(
Array keys,
Array values)
Parameters
Array keys
Keys to use for the array. Must contain only numeric or string values.
Array values
Values to use for the array.
Examples
Array_FromRange
Creates an array containing a range of numeric values. This can be used to run a for loop on a sequence of
numbers. For instance foreach ($i in Array_FromRange(1, 10, 1)) will iterate over numbers 1 to 10.
Syntax
void Array_FromRange(
Numeric start,
Numeric end,
Numeric step)
Parameters
Numeric start
The first value in the array.
Numeric end
The last value in the array.
Numeric step
The value to use as the increment between elements in the sequence. Can be positive for an increasing
sequence or negative for a decreasing sequence. The value of end must be reachable by repeatedly
incrementing start with step.
Examples
Array_Join
Concatenates the elements in the given array using the given glue string and returns the combined string.
Syntax
https://getonetastic.com/docs/OnetasticMacroDocumentation 75/156
11/11/24, 2:09 PM Onetastic Macro Documentation
String Array_Join(
Array array,
String glue)
Parameters
Array array
Array to join together into a string.
String glue
Glue string to add between the array elements.
Examples
Array_KeyExists
Returns whether a given key exists or not in the given array.
Syntax
Array Array_KeyExists(
Array array,
Mixed key)
Parameters
Array array
Array to look for the key in.
Mixed key
https://getonetastic.com/docs/OnetasticMacroDocumentation 76/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Array_Keys
Returns a new array that contains the keys of the given array.
Syntax
Parameters
Array array
Array to return the keys of.
Examples
$array2["color"] = "red"
$array2["size"] = "large"
$array2["type"] = "t-shirt"
$keys = Array_KeyExists($array2)
// $keys is ("color", "size", "type")
Array_Length
Returns the number of elements in the given array.
https://getonetastic.com/docs/OnetasticMacroDocumentation 77/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Syntax
Parameters
Array array
Array return the number of elements.
Examples
Array_Merge
Returns a new array that contains all the values in the given arrays. The values of each array are appended to the
end of the previous one. If the arrays have the same string keys, then the later value for that key will overwrite
the previous one. Numeric keys are not overwritten but instead will be appended. Values with numeric keys will
be renumbered with incrementing keys starting from zero in the result array.
Syntax
Parameters
$array = Array_Merge()
// $array is an empty array
$array1["size"] = "large"
$array1["color"] = "red"
$array2["size"] = "small"
$array2["type"] = "t-shirt"
$array3["color"] = "blue"
$array3["price"] = 10
https://getonetastic.com/docs/OnetasticMacroDocumentation 78/156
11/11/24, 2:09 PM Onetastic Macro Documentation
$array = Array_Merge($array1, $array2, $array3)
// This creates the following array:
// "size" => "small"
// "color" => "blue"
// "type" => "t-shirt"
// "price" => 10
Array_PopBack
Removes and returns the last element in the array. To use an array as a stack, use this function along with
Array_PushBack .
Syntax
Parameters
Array array
Array to remove and return the the last element from.
Examples
Array_PopFront
Removes and returns the first element in the array. All numerical keys in the array will be modified to start
counting from zero while string keys won't be affected. To use an array as a queue, use this function along with
Array_PushBack .
Syntax
Parameters
Array array
https://getonetastic.com/docs/OnetasticMacroDocumentation 79/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Array_PushBack
Inserts the given value to the end of the array. Returns the number of elements in the array after the insertion. To
use an array as a stack, use this function along with Array_PopBack . To use an array as a queue, use this function
along with Array_PopFront .
Syntax
https://getonetastic.com/docs/OnetasticMacroDocumentation 80/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Numeric Array_PushBack(
byref Array array,
Mixed value)
Parameters
Array array
Array to insert the value to.
Mixed value
The value to insert.
Examples
$array = Array(6, 4, 8)
$sizeAfterFirstPushBack = Array_PushBack($array, 3)
$sizeAfterSecondPushBack = Array_PushBack($array, 7)
// $array is now (6, 4, 8, 3, 7)
// $sizeAfterFirstPushBack is 4
// $sizeAfterSecondPushBack is 5
// If the array doesn't have numeric keys, new keys will start from 0
$array3["size"] = "large"
$array3["color"] = "red"
Array_PushBack($array3, "t-shirt")
Array_PushBack($array3, 10)
// $array3 is now:
// "size" => "large"
// "color" => "red"
// 0 => "t-shirt"
// 1 => 10
// If the array had some numeric keys, new keys will follow the largest one
$array4[7] = "a"
$array4[-2] = "b"
$array4["price"] = 100
Array_PushBack($array4, "first")
Array_PushBack($array4, "second")
// $array4 is now:
// 7 => "a"
// -2 => "b"
// "price" => 100
https://getonetastic.com/docs/OnetasticMacroDocumentation 81/156
11/11/24, 2:09 PM Onetastic Macro Documentation
// 8 => "first"
// 9 => "second"
Array_PushFront
Inserts the given value to the beginning of the array. All numerical keys in the array will be modified to start
counting from zero while string keys won't be affected. Returns the number of elements in the array after the
insertion.
Syntax
Numeric Array_PushFront(
byref Array array,
Mixed value)
Parameters
Array array
Array to insert the value to.
Mixed value
The value to insert.
Examples
$array = Array(6, 4, 8)
$sizeAfterFirstPushFront = Array_PushFront($array, 3)
$sizeAfterSecondPushFront = Array_PushFront($array, 7)
// $array is now (7, 3, 6, 4, 8)
// $sizeAfterFirstPushFront is 4
// $sizeAfterSecondPushFront is 5
https://getonetastic.com/docs/OnetasticMacroDocumentation 82/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Array_PushFront($array3, 6)
// $array3 is now:
// 0 => 6
// 1 => 8
// 2 => 10
// 3 => 12
Array_RemoveByKey
Removes the element with the given key from the array. Returns true if the key existed in the array and the
element is removed, false if the key didn't exist in the array.
Syntax
Bool Array_RemoveByKey(
byref Array array,
Mixed key)
Parameters
Array array
Array to remove the element from.
Mixed key
Key for the element to remove from the array.
Examples
https://getonetastic.com/docs/OnetasticMacroDocumentation 83/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Array_Reverse
Reverses the order of elements in the given array.
Syntax
void Array_Reverse(
byref Array array,
Bool preserveKeys)
Parameters
Array array
Array to reverse.
Bool preserveKeys
If true, the values in the array will have the same keys as before, but just order changed. If false, the values
will be assigned to new numeric keys starting from zero.
Examples
https://getonetastic.com/docs/OnetasticMacroDocumentation 84/156
11/11/24, 2:09 PM Onetastic Macro Documentation
// 4 => 2
Array_Shuffle
Randomizes the order of elements in the given array.
Syntax
void Array_Shuffle(
byref Array array,
Bool preserveKeys)
Parameters
Array array
Array to shuffle.
Bool preserveKeys
If true, the values in the array will have the same keys as before, but just order changed. If false, the values
will be assigned to new numeric keys starting from zero.
Examples
https://getonetastic.com/docs/OnetasticMacroDocumentation 85/156
11/11/24, 2:09 PM Onetastic Macro Documentation
// Shuffle, preserving keys
$array = Array(1, 2, 3, 4, 5, 6)
Array_Shuffle($array, true)
// $array may be now:
// 2 => 3
// 0 => 1
// 5 => 6
// 1 => 2
// 3 => 4
// 4 => 5
Array_Slice
Returns a new array containing a sequence of elements of the given array.
Syntax
Array Array_Slice(
Array array,
Numeric offset,
Numeric length,
Bool preserveKeys)
Parameters
Array array
Array to get elements from.
Numeric offset
The start offset to get elements. If non-negative, the sequence will start that far away from the beginning
of the array. If negative, the sequence will start that far away from the end of the array.
Numeric length
The length of the sequence. If there aren't that many elements in the array, the resulting array can be
shorter.
Bool preserveKeys
If true, the values in the resulting array will have the same keys as in the input array. If false, the resulting
array will have numeric keys starting from zero.
Examples
https://getonetastic.com/docs/OnetasticMacroDocumentation 86/156
11/11/24, 2:09 PM Onetastic Macro Documentation
$slice = Array_Slice($array, 4, 3, false)
// $slice is (5, 6, 7)
// First 4 elements
$slice = Array_Slice($array, 0, 4, false)
// $slice is (1, 2, 3, 4)
// Last 3 elements
$slice = Array_Slice($array, -3, 3, false)
// $slice is (8, 9, 10)
// Preserve keys
$slice = Array_Slice($array, 4, 3, true)
// $slice is:
// 4 => 5
// 5 => 6
// 6 => 7
Array_SortByKey
Sorts an array by the keys.
Syntax
Parameters
Array array
Array to sort.
Examples
$array["size"] = "large"
$array["type"] = "t-shirt"
$array["price"] = 10
$array["color"] = "red"
Array_SortByKey($array)
// $array is
// "color" => "red"
// "price" => 10
https://getonetastic.com/docs/OnetasticMacroDocumentation 87/156
11/11/24, 2:09 PM Onetastic Macro Documentation
// "size" => "large"
// "type" => "t-shirt"
Array_SortByValue
Sorts an array by the values.
Syntax
void Array_SortByValue(
byref Array array,
Bool preserveKeys)
Parameters
Array array
Array to sort.
Bool preserveKeys
If true, the values in the array will have the same keys as before, but just order changed. If false, the values
will be assigned to new numeric keys starting from zero.
Examples
$array = Array(6, 3, 7, 8, 4, 2, 3)
Array_SortByValue($array, false)
// $array is
// 0 => 2
// 1 => 3
// 2 => 3
// 3 => 4
// 4 => 6
// 5 => 7
// 6 => 8
// Preserve keys
$array = Array(6, 3, 7, 8, 4, 2, 3)
Array_SortByValue($array, true)
// $array is
// 5 => 2
// 1 => 3
// 6 => 3
// 4 => 4
// 0 => 6
// 2 => 7
// 3 => 8
https://getonetastic.com/docs/OnetasticMacroDocumentation 88/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Array_Splice
Removes a a sequence of elements of the given array and replaces it with the given array. Numeric keys in the
input array is not preseved and re-numbered from 0.
Syntax
void Array_Splice(
byref Array array,
Numeric offset,
Numeric length,
Array replacement)
Parameters
Array array
Array to remove and replace elements from.
Numeric offset
The start offset to remove and replace elements. If non-negative, the sequence will start that far away
from the beginning of the array. If negative, the sequence will start that far away from the end of the array.
Numeric length
The length of the sequence. If there aren't that many elements in the array, all the elements till the end of
the array will be removed and replaced. If given as zero, no elements will be removed but the new
elements will be inserted at given offset.
Array replacement
The set of elements to replace with. If this is an empty array, elements are removed only. Keys in the
replacement array is ignored.
Examples
// Remove 2 elements starting at 4th element from the end (98) and insert (0, -1, -2)
Array_Splice($array, -4, 2, Array(0, -1, -2))
// $array is (97, 0, -1, -2, 9, 10)
https://getonetastic.com/docs/OnetasticMacroDocumentation 89/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Array_Unique
Removes duplicate elements from the given array. Keys are preserved but the order of elements may be
changed.
Syntax
Parameters
Array array
Array to remove the duplicates from.
Examples
$array = Array(2, 6, 4, 3, 5, 9, 1, 2, 7, 5, 1, 4, 2, 6)
Array_Unique($array)
// $array is:
// 6 => 1
// 0 => 2
// 3 => 3
// 2 => 4
// 4 => 5
// 1 => 6
// 8 => 7
// 5 => 9
Array_ValueExists
https://getonetastic.com/docs/OnetasticMacroDocumentation 90/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Returns whether a given value exists or not in the given array. A variable is passed to the last parameter to
retrieve the key associated with the value if exists.
Syntax
Bool Array_ValueExists(
Array array,
Mixed value,
out Mixed key)
Parameters
Array array
Array to look for the value in.
Mixed value
Value to look for.
Array_Values
Returns a new array that contains the values of the given array. The new array will have numeric keys starting at
zero.
Syntax
Parameters
https://getonetastic.com/docs/OnetasticMacroDocumentation 91/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Array array
Array return the values of.
Examples
$array["color"] = "red"
$array["size"] = "large"
$array["type"] = "t-shirt"
$array["price"] = 10
$values = Array_Values($array)
// $values is ("red", "large", "t-shirt", 10)
IsArray
Returns whether a given expression is an array or not.
Syntax
Parameters
Mixed expression
Expression to check for.
Examples
IsArray(Array())
// true
IsArray(Array(1, 2, 3))
// true
IsArray(true)
// false
IsArray("string")
// false
IsArray(GetCurrentSection().pages)
// true
https://getonetastic.com/docs/OnetasticMacroDocumentation 92/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Color Functions
Color
Color
Creates a variable of type Color.
Syntax
Parameters
String value
The color value. Following string values are accepted:
#rrggbb: Red, green and blue values specified in lowercase hexadecimal (0-9, a-f)
#RRGGBB: Red, green and blue values specified in uppercase hexadecimal (0-9, A-F)
Examples
$color1 = Color("yellow")
$color1 == "#ffff00"
// True
$color2 = Color("#6A5ACD")
$color2 == "#6a5acd"
// True
$color2 == "SlateBlue"
// True
$color2 == "SpringGreen"
// False
LocalStore_Delete
LocalStore_Read
LocalStore_Write
https://getonetastic.com/docs/OnetasticMacroDocumentation 93/156
11/11/24, 2:09 PM Onetastic Macro Documentation
BinaryStore_Read
Reads file contents from the binary store and returns it. The return value can be assigned to data property of
Image or EmbeddedFile objects. See more about this at Using Binary Data.
Syntax
Parameters
String name
The name of the file to read from the binary store.
LocalStore_Delete
Deletes the value stored under given key for this macro on the local computer. The value would have been saved
by LocalStore_Write function in a previous execution of this macro. See more about this at Storing persistent
data.
Syntax
Parameters
String key
The key to delete.
LocalStore_Read
Reads the value stored under the given key for this macro on the local computer. Returns true if the key has been
found and the value is stored in the out parameter, false otherwise. The value must have been stored previously
using LocalStore_Write function in either the current or a previous execution of this macro. See more about this
at Storing Persistent Data.
Syntax
Bool LocalStore_Read(
String key,
https://getonetastic.com/docs/OnetasticMacroDocumentation 94/156
11/11/24, 2:09 PM Onetastic Macro Documentation
out Mixed value)
Parameters
String key
The key the value was stored under previously.
LocalStore_Write
Saves given key-value pair for this macro on the local computer. The value can be retrieved later using
LocalStore_Read function even in a subsequent execution of this macro. See more about this at Storing
persistent data.
Syntax
void LocalStore_Write(
String key,
Mixed value)
Parameters
String key
The key to store the value under.
Mixed value
The value to store. This can be any type other than an Object. If it is an Array, it cannot contain Objects.
Date/Time Functions
Date/Time Manipulation Functions
DateTime_Now
DateTime_FromString
DateTime_ToString
DateTime_Add
DateTime_Subtract
DateTime
https://getonetastic.com/docs/OnetasticMacroDocumentation 95/156
11/11/24, 2:09 PM Onetastic Macro Documentation
TimeSpan
DateTime_ShortDate
DateTime_Year
DateTime_Month
DateTime_Day
DateTime_DayOfTheYear
DateTime_DayOfTheWeek_Long
DateTime_DayOfTheWeek_Short
DateTime_MonthName_Long
DateTime_MonthName_Short
DateTime_DaysSinceSunday
DateTime_LongTime
DateTime_ShortTime
DateTime_Hour
DateTime_Min
DateTime_Sec
DateTime_Now
Returns the current date/time.
Syntax
DateTime DateTime_Now()
Parameters
This function has no parameters
DateTime_FromString
Returns a date/time value by parsing a string representation of it.
Syntax
https://getonetastic.com/docs/OnetasticMacroDocumentation 96/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Parameters
String dateStr
String value to parse into a date/time object. It needs to be in the following format: YYYY-MM-DDTHH-MM-
SS.000Z as specified at http://www.w3.org/TR/xmlschema-2/#dateTime.
Examples
$date = DateTime_FromString("2022-10-05T22:33:00.000Z")
// 2022-10-05 22:33 UTC
DateTime_ToString
Returns a string representation of a date/time value in local or UTC timezone. The format of the string is the
following: YYYY-MM-DDTHH-MM-SS.000Z as specified at http://www.w3.org/TR/xmlschema-2/#dateTime.
Syntax
String DateTime_ToString(
DateTime date,
Bool local)
Parameters
DateTime date
Date/time value to convert to string.
Bool local
Whether to output in local timezone or UTC.
Examples
DateTime_Add
Returns a new date/time value by adding the given time span to the given date/time value.
Syntax
DateTime DateTime_Add(
DateTime date,
https://getonetastic.com/docs/OnetasticMacroDocumentation 97/156
11/11/24, 2:09 PM Onetastic Macro Documentation
TimeSpan timespan)
Parameters
DateTime date
Date/time value to add to.
TimeSpan timespan
Time span amount to add.
Examples
$now = DateTime_Now()
DateTime_Subtract
Returns a new date/time value by subtracting the given time span from the given date/time value. It can also be
used to subtract two date/time values to find the difference between them as a time span value.
Syntax
Mixed DateTime_Subtract(
DateTime date,
Mixed dateOrTimespan)
Parameters
DateTime date
Date/time value to add to.
Mixed dateOrTimespan
Time span amount to subtract, or second date/time value to find the difference.
Examples
$now = DateTime_Now()
https://getonetastic.com/docs/OnetasticMacroDocumentation 98/156
11/11/24, 2:09 PM Onetastic Macro Documentation
DateTime
Returns a date/time value from given year, month, day, hour, minute, and second values. Hour, minute, and
second values are optional. The returned date/time value is in the local timezone of the current computer.
Syntax
DateTime DateTime(
Integer year,
Integer month,
Integer day,
Integer hour,
Integer min,
Integer sec)
Parameters
Integer year
Year value.
Integer month
Month value.
Integer day
Day value.
https://getonetastic.com/docs/OnetasticMacroDocumentation 99/156
11/11/24, 2:09 PM Onetastic Macro Documentation
TimeSpan
Returns a time span value that can be added or subtracted from a date/time object using DateTime_Add and
DateTime_Subtract functions.
Syntax
TimeSpan TimeSpan(
Integer amount,
String unit)
Parameters
Integer amount
Amount of time, based on the unit.
String unit
Unit for the timespan. Can be one of sec, min, hour, or day.
Examples
$now = DateTime_Now()
DateTime_LongDate
Returns the date portion of the given date/time in long date format.
Syntax
Parameters
DateTime dateTime
DateTime value to return the date portion of.
https://getonetastic.com/docs/OnetasticMacroDocumentation 100/156
11/11/24, 2:09 PM Onetastic Macro Documentation
DateTime_ShortDate
Returns the date portion of the given date/time in short date format.
Syntax
Parameters
DateTime dateTime
DateTime value to return the date portion of.
DateTime_Year
Returns the year of the given date/time.
Syntax
Parameters
DateTime dateTime
DateTime value to return the month portion of.
DateTime_Month
Returns the month (1-12) of the given date/time.
Syntax
Parameters
DateTime dateTime
DateTime value to return the month portion of.
DateTime_Day
Returns the day of the month (1-31) of the given date/time.
https://getonetastic.com/docs/OnetasticMacroDocumentation 101/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Syntax
Parameters
DateTime dateTime
DateTime value to return the day portion of.
DateTime_DayOfTheYear
Returns the day of the year (1-366) of the given date/time.
Syntax
Parameters
DateTime dateTime
DateTime value to return the day portion of.
DateTime_DayOfTheWeek_Long
Returns the day of the week of the given date/time in long format.
Syntax
Parameters
DateTime dateTime
DateTime value to return the day portion of.
DateTime_DayOfTheWeek_Short
Returns the day of the week of the given date/time in short format.
Syntax
https://getonetastic.com/docs/OnetasticMacroDocumentation 102/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Parameters
DateTime dateTime
DateTime value to return the day portion of.
DateTime_MonthName_Long
Returns the name of the month of the given date/time in long format.
Syntax
Parameters
DateTime dateTime
DateTime value to return the month portion of.
DateTime_MonthName_Short
Returns the name of the month of the given date/time in short format.
Syntax
Parameters
DateTime dateTime
DateTime value to return the month portion of.
DateTime_DaysSinceSunday
Returns the number of days passed since Sunday for the given date/time.
Syntax
https://getonetastic.com/docs/OnetasticMacroDocumentation 103/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Parameters
DateTime dateTime
DateTime value to return the days portion of.
DateTime_LongTime
Returns the time portion of the given date/time in long format.
Syntax
Parameters
DateTime dateTime
DateTime value to return the time portion of.
DateTime_ShortTime
Returns the time portion of the given date/time in short format.
Syntax
Parameters
DateTime dateTime
DateTime value to return the time portion of.
DateTime_Hour
Returns the hour (0-23) of the given date/time.
Syntax
Parameters
DateTime dateTime
https://getonetastic.com/docs/OnetasticMacroDocumentation 104/156
11/11/24, 2:09 PM Onetastic Macro Documentation
DateTime_Min
Returns the minute (0-59) of the given date/time.
Syntax
Parameters
DateTime dateTime
DateTime value to return the minute portion of.
DateTime_Sec
Returns the second (0-59) of the given date/time.
Syntax
Parameters
DateTime dateTime
DateTime value to return the second portion of.
DialogBox_AddCheckBox
DialogBox_AddColorPicker
DialogBox_AddComboBox
DialogBox_AddDateTimePicker
DialogBox_AddDropDown
DialogBox_AddFontPicker
DialogBox_AddLabel
DialogBox_AddRadioGroup
https://getonetastic.com/docs/OnetasticMacroDocumentation 105/156
11/11/24, 2:09 PM Onetastic Macro Documentation
DialogBox_AddTextBox
DialogBox_Create
DialogBox_SetControlEnabled
DialogBox_SetControlVisible
DialogBox_SetEventHandler
DialogBox_Show
ShowMessage
ShowTaskDialog
DialogBox_AddButton
Adds a custom button to a dialog box.
Syntax
void DialogBox_AddButton(
DialogBox dialogBox,
String label,
String name)
Parameters
DialogBox dialogBox
The dialogBox to add the button to.
String label
A label for the button. If there is an ampersand (&) sign before a character in the label it becomes the
button's accelerator key.
String name
Name of the button. When a dialog box is closed by clicking on this button, DialogBox_Show function will
return the name of the button that was clicked.
Remarks
If no custom buttons are added to a dialog box, it will automatically have an "OK" button when it is displayed. Up
to 4 buttons can be added to a dialog box. When the user clicks on a button the dialog box closes and
DialogBox_Show function will return the name of the button that was clicked
Examples
https://getonetastic.com/docs/OnetasticMacroDocumentation 106/156
11/11/24, 2:09 PM Onetastic Macro Documentation
DialogBox_AddButton($dialog, "&No", "no")
if ("yes" == DialogBox_Show($dialog))
RemoveObject($page)
After user clicks on one of the "Yes" and "No" buttons, DialogBox_Show function returns either "yes" or "no", the
name of the button user clicked.
DialogBox_AddCheckBox
Adds a checkbox to a dialog box.
Syntax
void DialogBox_AddCheckBox(
DialogBox dialogBox,
String label,
String name,
Bool initialValue)
Parameters
DialogBox dialogBox
The dialog box to add the checkbox to.
String label
A label for the checkbox.
String name
Name of the checkbox. The value of the checkbox will be stored dialogBox.controls[name] after the
dialog is displayed using DialogBox_Show function.
Bool initialValue
The initial value of the checkbox.
https://getonetastic.com/docs/OnetasticMacroDocumentation 107/156
11/11/24, 2:09 PM Onetastic Macro Documentation
DialogBox_AddColorPicker
Adds a color picker control to a dialog box.
Syntax
void DialogBox_AddColorPicker(
DialogBox dialogBox,
String label,
String name,
String initialValue)
Parameters
DialogBox dialogBox
The dialog box to add the color picker to.
String label
A label for the color picker.
String name
Name of the color picker. The color picked from the color picker will be stored dialogBox.controls[name]
String initialValue
The initial selected value of the color picker.
DialogBox_AddComboBox
Adds a drop down combo box to a dialog box.
Syntax
void DialogBox_AddComboBox(
DialogBox dialogBox,
String label,
String name,
String initialValue,
Array<String> possibleValues,
Bool emptyOK)
Parameters
DialogBox dialogBox
The dialog box to add the drop down combo box to.
https://getonetastic.com/docs/OnetasticMacroDocumentation 108/156
11/11/24, 2:09 PM Onetastic Macro Documentation
String label
A label for the drop down combo box.
String name
Name of the drop down combo box. The value of the drop down combo box will be stored
dialogBox.controls[name] after the dialog is displayed using DialogBox_Show function.
String initialValue
The initial selected value of the drop down combo box.
Array<String> possibleValues
The values to display in the drop down combo box.
Bool emptyOK
Whether it is OK for user to leave the combo box empty or not. If this is false, then the dialog box cannot
be closed without entering some text into the combo box.
DialogBox_AddDateTimePicker
Adds a date/time picker control to a dialog box.
Syntax
void DialogBox_AddDateTimePicker(
DialogBox dialogBox,
String label,
String name,
DateTime initialValue,
DateTimePickerType type)
Parameters
DialogBox dialogBox
The dialog box to add the date/time picker to.
String label
A label for the date/time picker.
String name
Name of the date/time picker. The date/time picked from the date/time picker will be stored
dialogBox.controls[name] after the dialog is displayed using DialogBox_Show function.
DateTime initialValue
The initial selected date/time of the date/time picker.
https://getonetastic.com/docs/OnetasticMacroDocumentation 109/156
11/11/24, 2:09 PM Onetastic Macro Documentation
DateTimePickerType type
The type of date/time picker. Can have the values "date", "time", or "datetime".
DialogBox_AddDropDown
Adds a drop down list box to a dialog box.
Syntax
void DialogBox_AddDropDown(
DialogBox dialogBox,
String label,
String name,
String initialValue,
Array<String> possibleValues)
Parameters
DialogBox dialogBox
The dialog box to add the drop down list box to.
String label
A label for the drop down list box.
String name
Name of the drop down list box. The value of the drop down list box will be stored
dialogBox.controls[name] after the dialog is displayed using DialogBox_Show function.
String initialValue
The initial selected value of the drop down list box.
Array<String> possibleValues
The values to display in the drop down list box.
DialogBox_AddFontPicker
Adds a font picker control to a dialog box.
Syntax
void DialogBox_AddFontPicker(
DialogBox dialogBox,
String label,
https://getonetastic.com/docs/OnetasticMacroDocumentation 110/156
11/11/24, 2:09 PM Onetastic Macro Documentation
String name,
String initialValue)
Parameters
DialogBox dialogBox
The dialog box to add the font picker to.
String label
A label for the font picker.
String name
Name of the font picker. The font picked from the font picker will be stored dialogBox.controls[name]
String initialValue
The initial selected value of the font picker.
DialogBox_AddLabel
Adds a label to a dialog box.
Syntax
void DialogBox_AddLabel(
DialogBox dialogBox,
String label)
Parameters
DialogBox dialogBox
The dialog box to add the text box to.
String label
A text for the label.
DialogBox_AddRadioGroup
Adds a group of radio buttons to a dialog box. User can choose at most one of the options in the group.
Syntax
https://getonetastic.com/docs/OnetasticMacroDocumentation 111/156
11/11/24, 2:09 PM Onetastic Macro Documentation
void DialogBox_AddRadioGroup(
DialogBox dialogBox,
String label,
String name,
String initialValue,
Array<String> possibleValues)
Parameters
DialogBox dialogBox
The dialog box to add the radio group to.
String label
A label for the whole group.
String name
Name of the radio group. The value of the selected option will be stored dialogBox.controls[name] after
the dialog is displayed using DialogBox_Show function.
String initialValue
The initial selected option among the group.
Array<String> possibleValues
The list of options to display.
DialogBox_AddTextBox
Adds a text box to a dialog box.
Syntax
void DialogBox_AddTextBox(
DialogBox dialogBox,
String label,
String name,
String initialValue,
Bool emptyOK)
Parameters
DialogBox dialogBox
The dialog box to add the text box to.
String label
https://getonetastic.com/docs/OnetasticMacroDocumentation 112/156
11/11/24, 2:09 PM Onetastic Macro Documentation
String name
Name of the text box. The value of the text box will be stored dialogBox.controls[name] after the dialog
is displayed using DialogBox_Show function.
String initialValue
The initial value of the text box.
Bool emptyOK
Whether it is OK for user to leave the text box empty or not. If this is false, then the dialog box cannot be
closed without entering some text into the text box.
DialogBox_Create
Creates a dialog box. Use DialogBox_Add* functions to add controls and DialogBox_Show to display it.
Syntax
Parameters
String message
A message to display on the dialog box. Can be empty string if no message is desired.
DialogBox_SetControlEnabled
Enables or disables a control in a dialog box. This function can be called prior to displaying a dialog box via
DialogBox_Show or during a dialog box event handler set by DialogBox_SetEventHandler .
Syntax
void DialogBox_SetControlEnabled(
DialogBox dialogBox,
String controlName,
Bool enabled)
Parameters
DialogBox dialogBox
The dialog box that contains the control to enable or disable.
https://getonetastic.com/docs/OnetasticMacroDocumentation 113/156
11/11/24, 2:09 PM Onetastic Macro Documentation
String controlName
The name of the control to enable or disable.
Bool enabled
Whether to enable or to disable the control.
DialogBox_SetControlVisible
Hides or shows a control in a dialog box. This function can be called prior to displaying a dialog box via
DialogBox_Show or during a dialog box event handler set by DialogBox_SetEventHandler .
Syntax
void DialogBox_SetControlVisible(
DialogBox dialogBox,
String controlName,
Bool visible)
Parameters
DialogBox dialogBox
The dialog box that contains the control to hide or show.
String controlName
The name of the control to hide or show.
Bool visible
Whether to hide or to show the control.
DialogBox_SetEventHandler
Sets an event handler for a dialog box.
Syntax
void DialogBox_SetEventHandler(
DialogBox dialogBox,
String functionName)
Parameters
DialogBox dialogBox
The dialog box to set the event handler for.
https://getonetastic.com/docs/OnetasticMacroDocumentation 114/156
11/11/24, 2:09 PM Onetastic Macro Documentation
String functionName
Name of the user defined function to set as an event handler for the dialog.
Remarks
An event handler is a user defined function that gets called when the dialog is first created and then each time
when value of one of the controls in the dialog box changes (e.g. user types into a text box, checks a check box, or
chooses an option from a dropdown box etc.) or user clicks a custom button. Event handlers are not required to
be set for a dialog box but can be used for more control on what controls are visible or enabled under specific
conditions. The signature of an event handler is as follows:
The first parameter is the dialog box that the event is coming from. The second parameter is the name of the
control which the event is originating from. When the event handler is called the first time when the dialog is
created, control name will be empty. In the subsequent calls, in case of a value change this will be the name of
the corresponding color picker, combo box, date/time picker, drop down, font picker, radio group or text box. In
case of a button click, this will be the name of the button.
If there are no custom buttons added to a dialog box, it will display the default "OK" button. In this case, if user
clicks on the "OK" button:
If there are custom buttons added to a dialog box (via DialogBox_AddButton ), and the user clicks on one of the
buttons, the handling of the dialog depends on whether an event handler is set or not:
https://getonetastic.com/docs/OnetasticMacroDocumentation 115/156
11/11/24, 2:09 PM Onetastic Macro Documentation
The dialog is not closed and user can continue to interact with the dialog
DialogBox_Show
Displays a dialog box created with DialogBox_Create function. If a dialog box is closed by clicking on one of the
action buttons, DialogBox_Show will return the name of the button. If no custom buttons are added by
DialogBox_AddButton to the dialog box, then user can click on the default "OK" button and DialogBox_Show will
then return "ok".
Syntax
Parameters
DialogBox dialogBox
The dialog box object to display.
ShowMessage
Shows a message to the user in a message box with OK button. Macro execution continues after user closes the
message box.
Syntax
Parameters
String message
A message to display to the user in a message box.
Remarks
A message box contains the macro name as a title and the given message. It may look like this:
https://getonetastic.com/docs/OnetasticMacroDocumentation 116/156
11/11/24, 2:09 PM Onetastic Macro Documentation
User can click OK or close the dialog using the X button. In either case macro execution will continue.
Examples
ShowTaskDialog
Shows a task dialog to the user with a number of command buttons to choose from.
Syntax
Integer ShowTaskDialog(
String title,
String message,
Array<String> buttons)
Parameters
String title
A title for the task dialog.
String message
A message for the task dialog that will show below the title.
Array<String> buttons
An array of button labels.
Remarks
A task dialog contains a title, a message and a set of command buttons. It may look like this:
https://getonetastic.com/docs/OnetasticMacroDocumentation 117/156
11/11/24, 2:09 PM Onetastic Macro Documentation
User can click one of the command buttons or close the dialog. If user clicks one of the buttons, the dialog will
close and this function will return the index of the button in the given button array (0 for the first button, 1 for the
second button etc). If user closes the dialog using the X button on the top right corner, then macro execution will
stop.
Examples
$message = "You can save the currently selected text as a snippet to be used for
later, or you can insert one of the previously saved snippets to the current page."
switch ($selected)
case 0:
// User selected first option
break 1
case 1:
// User selected second option
break 1
case 2:
// User selected third option
break 1
SaveChanges
ExitMacro
Exits the macro execution while optionally saving any changes made to OneNote. To save changes without exiting
macro execution, use the SaveChanges function.
Syntax
Parameters
https://getonetastic.com/docs/OnetasticMacroDocumentation 118/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Bool saveChanges
Saves any changes made by this macro to OneNote if set to true, discards them if set to false.
SaveChanges
Saves any changes made by this macro to OneNote. After changes are saved, all objects within any modified
pages are invalidated. That is, if there are variables that are holding objects within such a page (e.g. Outlines ,
Paragraphs , Text objects etc.) they will be invalid and should not be used again. To get to those objects again,
access them through a Page object. Objects within unmodified pages are unaffected.
Macros normally save any changes they made to OneNote at the end of macro execution, except if the execution
is terminated by a call to ExitMacro(false) . Therefore, it is typically not necessary to use this function. However,
there are some cases where you may want to save changes before macro execution ends. For example this
function can be useful to obtain certain properties that will only be available after saving changes or to provide
incremental updates to the user.
Syntax
void SaveChanges()
Parameters
This function has no parameters
Examples
https://getonetastic.com/docs/OnetasticMacroDocumentation 119/156
11/11/24, 2:09 PM Onetastic Macro Documentation
SaveChanges()
MacroMenu_AddItem
Adds a menu item to current macro's menu. Macros can optionally display a menu with multiple items. See Macro
menus for more information.
Syntax
void MacroMenu_AddItem(
MacroMenu menu,
String argument,
String label,
String description)
Parameters
MacroMenu menu
The menu to add menu item to. This object will be passed to the Setup function.
String argument
The argument passed to the Main function if this menu item is clicked.
String label
The label to be displayed in the ribbon for this menu item.
String description
The description to be displayed in the ribbon for this menu item.
https://getonetastic.com/docs/OnetasticMacroDocumentation 120/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Object Functions
GetAncestorOfType
GetCurrentNotebook
GetCurrentPage
GetCurrentSection
GetCurrentSectionGroup
GetNotebookRoot
GetParentOfType
InsertObject
IsObject
QueryObjects
QueryText
RemoveObject
SortObjects
GetAncestorOfType
Returns true if the given object has an ancestor of given type and stores that ancestor in the ancestor parameter.
Syntax
Bool GetAncestorOfType(
Object object,
ObjectType type,
out Object ancestor)
Parameters
Object object
Object to look for an ancestor of.
ObjectType type
Type of the ancestor to look for.
https://getonetastic.com/docs/OnetasticMacroDocumentation 121/156
11/11/24, 2:09 PM Onetastic Macro Documentation
GetCurrentNotebook
Returns the current notebook in OneNote.
Syntax
Notebook GetCurrentNotebook()
Parameters
This function has no parameters
GetCurrentPage
Returns the current page in OneNote.
Syntax
Page GetCurrentPage()
Parameters
This function has no parameters
GetCurrentSection
Returns the current section in OneNote.
Syntax
Section GetCurrentSection()
Parameters
https://getonetastic.com/docs/OnetasticMacroDocumentation 122/156
11/11/24, 2:09 PM Onetastic Macro Documentation
GetCurrentSectionGroup
Returns the current section group in OneNote. If the current section is not in a section group, then returns the
current Notebook.
Syntax
Mixed GetCurrentSectionGroup()
Parameters
This function has no parameters
GetNotebookRoot
Returns the root of the notebook hierarchy in OneNote.
Syntax
NotebookRoot GetNotebookRoot()
Parameters
This function has no parameters
GetParentOfType
Returns true if the given object has a parent of given type and stores that parent in the parent parameter.
Syntax
Bool GetParentOfType(
Object object,
ObjectType type,
out Object parent)
Parameters
Object object
Object to look for a parent of.
https://getonetastic.com/docs/OnetasticMacroDocumentation 123/156
11/11/24, 2:09 PM Onetastic Macro Documentation
ObjectType type
Type of the parent to look for.
InsertObject
Creates a new object and inserts it into OneNote hierarchy or into a OneNote page. Returns the newly created
object.
Syntax
Object InsertObject(
Object object,
ObjectType type,
Numeric position)
Parameters
Object object
Parent object to insert the new object into.
ObjectType type
The type of the new object to create and insert. Following types of objects can be inserted:
Type Remarks
https://getonetastic.com/docs/OnetasticMacroDocumentation 124/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Numeric position
The position of the new object. The value is a 0 based index for the child collection or -1 to insert at the
end.
IsObject
Returns whether a given expression is an object or not.
Syntax
Parameters
Mixed expression
Expression to check for.
Examples
IsObject(GetCurrentPage())
// true
IsObject(Array(1, 2, 3))
// false
IsObject(true)
// false
IsObject("string")
// false
https://getonetastic.com/docs/OnetasticMacroDocumentation 125/156
11/11/24, 2:09 PM Onetastic Macro Documentation
IsObject(Window_GetCurrent())
// true
QueryObjects
Queries requested type of object in OneNote within the given scope. Returns all found object in an array. Search
is done in a depth-first manner.
Syntax
Array<Object> QueryObjects(
ObjectType type,
Object scope)
Parameters
ObjectType type
Type of the object to query for.
Object scope
Root object for the search. All objects under this object (including this object) are searched.
QueryText
Queries given text in OneNote within the given scope. Returns all found text object in an array. Search is done in a
depth-first manner.
Syntax
Array<Text> QueryText(
Object scope,
String value,
Bool ignorecase)
Parameters
Object scope
Root object for the search. All text under this object (including this object) are searched.
String value
The text value to search for.
https://getonetastic.com/docs/OnetasticMacroDocumentation 126/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Bool ignorecase
Find text in case-insensitive manner if set to true.
RemoveObject
Removes the given object from its parent object. The object must have a parent object. This can be used to delete
content from a Page or whole pages. Certain container objects will only be valid with at least one child, and
therefore removing the last child will result in a schema error. For instance Outline and Cell objects require at
least one Paragraph inside them.
Syntax
Parameters
Object object
The object to remove.
SortObjects
Sorts given objects by a given property or a given custom sort order. When sorting object that are not under the
same parent object, they are sorted only within their siblings. For instance if you try to sort all pages in current
notebook, they will be sorted within each section and they won't move between sections.
Syntax
void SortObjects(
Array objects,
Mixed by,
Bool ascending)
Parameters
Array objects
Array of objects to be sorted.
Mixed by
The property to sort by (in which case its type is string) or a custom sort order (in which case its type is an
array). A custom sort order array must have indices 0 to number of elements being sorted and its values
will be used when comparing corresponding object in the object array.
https://getonetastic.com/docs/OnetasticMacroDocumentation 127/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Bool ascending
Sort in ascending order, if set to true, descending order if set to false.
Special Functions
Main
Setup
Main
The main function of a macro. Every macro has a Main function and the statements of the Main function are
executed when the macro is ran.
Syntax
Parameters
String arg
The argument passed into the Main function through a menu item. If the macro is executed by its main
button on the ribbon, the value of this parameter is empty string.
Setup
The function that will get called whenever Onetastic needs to get a macro's menu to be displayed in the ribbon.
See more about this function at Macro menus.
Syntax
Parameters
MacroMenu menu
The menu object for this function.
Examples
https://getonetastic.com/docs/OnetasticMacroDocumentation 128/156
11/11/24, 2:09 PM Onetastic Macro Documentation
String Functions
Chr
String_Contains
String_DoesNotEqual
String_EndsWith
String_Equals
String_FindFirst
String_FindFirstNotOf
String_FindFirstOf
String_FindLast
String_FindLastNotOf
String_FindLastOf
String_GreaterThan
String_GreaterThanOrEqualTo
String_Insert
String_Length
String_LessThan
String_LessThanOrEqualTo
String_Pad
String_Repeat
String_Replace
String_Reverse
String_Split
String_StartsWith
String_Substring
String_ToLowerCase
String_ToUpperCase
String_Trim
https://getonetastic.com/docs/OnetasticMacroDocumentation 129/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Chr
Creates a string from a given ASCII number or Unicode code point. For instance Chr(10) will return the newline
character "\n".
Syntax
Parameters
Chr(65)
// "A"
Chr(9924, 9917)
// "⛄⚽"
String_Contains
Returns true if the first string contains the second string, false otherwise.
Syntax
Bool String_Contains(
String first,
String second,
Bool ignorecase)
Parameters
String first
https://getonetastic.com/docs/OnetasticMacroDocumentation 130/156
11/11/24, 2:09 PM Onetastic Macro Documentation
String second
Second string to compare.
Bool ignorecase
Ignores the case of the strings if set to true.
Examples
// case Sensitive
String_Contains("The quick brown fox", "Quick", false)
// false
// case Insensitive
String_Contains("The quick brown fox", "Quick", true)
// true
String_DoesNotEqual
Returns true if the given two strings are not equal, false otherwise.
Syntax
Bool String_DoesNotEqual(
String first,
String second,
Bool ignorecase)
Parameters
String first
First string to compare.
String second
Second string to compare.
Bool ignorecase
Ignores the case of the strings if set to true.
Examples
https://getonetastic.com/docs/OnetasticMacroDocumentation 131/156
11/11/24, 2:09 PM Onetastic Macro Documentation
// case Sensitive
String_DoesNotEqual("Strawberry", "strawberry", false)
// true
// case Insensitive
String_DoesNotEqual("Strawberry", "strawberry", true)
// false
String_EndsWith
Returns true if the first string ends with the second string, false otherwise.
Syntax
Bool String_EndsWith(
String first,
String second,
Bool ignorecase)
Parameters
String first
First string to compare.
String second
Second string to compare.
Bool ignorecase
Ignores the case of the strings if set to true.
Examples
// case Sensitive
String_EndsWith("The quick brown fox", "Fox", false)
// false
// case Insensitive
String_EndsWith("The quick brown fox", "Fox", true)
// true
https://getonetastic.com/docs/OnetasticMacroDocumentation 132/156
11/11/24, 2:09 PM Onetastic Macro Documentation
String_Equals
Returns true if the given two strings are equal, false otherwise.
Syntax
Bool String_Equals(
String first,
String second,
Bool ignorecase)
Parameters
String first
First string to compare.
String second
Second string to compare.
Bool ignorecase
Ignores the case of the strings if set to true.
Examples
// case Sensitive
String_Equals("Strawberry", "strawberry", false)
// false
// case Insensitive
String_Equals("Strawberry", "strawberry", true)
// true
String_FindFirst
Finds the first occurence of a search string in an input string. Returns true if the string was found and the offset it
was found at, false otherwise.
Syntax
https://getonetastic.com/docs/OnetasticMacroDocumentation 133/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Bool String_FindFirst(
String string,
String search,
Numeric offset,
Bool ignorecase,
out Numeric foundAt)
Parameters
String string
String to search in.
String search
The substring to search for.
Numeric offset
Offset of the input string to start search from. If non-negative, search will start this number of characters
counted from the beginning of the string. If negative, the search will start this number of characters
counted from the end of the string.
Bool ignorecase
Ignores the case of the strings if set to true.
// 1 2 3 4
// 01234567890123456789012345678901234567890
$string = "a4 b6 c5 4a b6 d5 f6 d7 e4 b6 c2 56 d4 5a"
// ^ ^ ^
// Instances of b6 are marked with ^
// Not found
https://getonetastic.com/docs/OnetasticMacroDocumentation 134/156
11/11/24, 2:09 PM Onetastic Macro Documentation
String_FindFirst($string, "f9", 0, false, $foundAt)
// Returns false, $foundAt is not modified
// case Sensitive
String_FindFirst("The quick brown fox jumps over the lazy dog", "the", 0, false,
$foundAt)
// Returns true, $foundAt is 31
// case Insensitive
String_FindFirst("The quick brown fox jumps over the lazy dog", "the", 0, true,
$foundAt)
// Returns true, $foundAt is 0
String_FindFirstNotOf
Finds the first character that does not match any of given the characters in an input string. Returns true if it was
found and the offset it was found at, false otherwise.
Syntax
Bool String_FindFirstNotOf(
String string,
String characters,
Numeric offset,
out Numeric foundAt)
Parameters
String string
String to search in.
String characters
The set of characters to look for.
Numeric offset
Offset of the input string to start search from. If non-negative, search will start this number of characters
counted from the beginning of the string. If negative, the search will start this number of characters
counted from the end of the string.
https://getonetastic.com/docs/OnetasticMacroDocumentation 135/156
11/11/24, 2:09 PM Onetastic Macro Documentation
// 1 2 3 4
// 01234567890123456789012345678901234567890
$string = "a4 b6 c5 4a b6 d5 f6 d7 e4 b6 c2 56 d4 5a"
// ^ ^ ^ ^
// Instances of c, 7 and f are marked with ^
// Not found
String_FindFirstNotOf($string, "abcdef24567", 0, $foundAt)
// Returns false, $foundAt is not modified
String_FindFirstOf
Finds the first occurence of any of the given characters in an input string. Returns true if one was found and the
offset it was found at, false otherwise.
Syntax
Bool String_FindFirstOf(
String string,
String characters,
Numeric offset,
out Numeric foundAt)
Parameters
String string
String to search in.
String characters
The set of characters to look for.
Numeric offset
https://getonetastic.com/docs/OnetasticMacroDocumentation 136/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Offset of the input string to start search from. If non-negative, search will start this number of characters
counted from the beginning of the string. If negative, the search will start this number of characters
counted from the end of the string.
// 1 2 3 4
// 01234567890123456789012345678901234567890
$string = "a4 b6 c5 4a b6 d5 f6 d7 e4 b6 c2 56 d4 5a"
// ^ ^ ^ ^
// Instances of c, 7 and f are marked with ^
// Not found
String_FindFirstOf($string, "abc", 0, $foundAt)
// Returns false, $foundAt is not modified
String_FindLast
Finds the last occurence of a search string in an input string. Returns true if the string was found and the offset it
was found at, false otherwise.
Syntax
Bool String_FindLast(
String string,
String search,
Numeric offset,
Bool ignorecase,
out Numeric foundAt)
https://getonetastic.com/docs/OnetasticMacroDocumentation 137/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Parameters
String string
String to search in.
String search
The substring to search for.
Numeric offset
Offset of the input string to start search from. If positive, search will only look at this number of characters
at the beginning of the string. If negative, the search will not include this number of characters at the end
of the string. If zero, the search will include the whole string.
Bool ignorecase
Ignores the case of the strings if set to true.
// 1 2 3 4
// 01234567890123456789012345678901234567890
$string = "a4 b6 c5 4a b6 d5 f6 d7 e4 b6 c2 56 d4 5a"
// ^ ^ ^
// Instances of b6 are marked with ^
// Not found
String_FindLast($string, "f9", 0, false, $foundAt)
// Returns false, $foundAt is not modified
// case Sensitive
String_FindLast("The quick brown fox jumps over the lazy dog", "The", 0, false,
$foundAt)
// Returns true, $foundAt is 0
https://getonetastic.com/docs/OnetasticMacroDocumentation 138/156
11/11/24, 2:09 PM Onetastic Macro Documentation
// case Insensitive
String_FindLast("The quick brown fox jumps over the lazy dog", "The", 0, true,
$foundAt)
// Returns true, $foundAt is 31
String_FindLastNotOf
Finds the last character that does not match any of given the characters in an input string. Returns true if it was
found and the offset it was found at, false otherwise.
Syntax
Bool String_FindLastNotOf(
String string,
String characters,
Numeric offset,
out Numeric foundAt)
Parameters
String string
String to search in.
String characters
The set of characters to look for.
Numeric offset
Offset of the input string to start search from. If non-negative, search will start this number of characters
counted from the beginning of the string, going backwards. If negative, the search will start this number of
characters counted from the end of the string, going backwards.
// 1 2 3 4
// 01234567890123456789012345678901234567890
$string = "a4 b6 c5 4a b6 d5 f6 d7 e4 b6 c2 56 d4 5a"
// ^ ^ ^ ^
// Instances of c, 7 and f are marked with ^
https://getonetastic.com/docs/OnetasticMacroDocumentation 139/156
11/11/24, 2:09 PM Onetastic Macro Documentation
// Returns true, $foundAt is 30
// Not found
String_FindLastNotOf($string, "abcdef24567", 0, $foundAt)
// Returns false, $foundAt is not modified
String_FindLastOf
Finds the last occurence of any of the given characters in an input string. Returns true if one was found and the
offset it was found at, false otherwise.
Syntax
Bool String_FindLastOf(
String string,
String characters,
Numeric offset,
out Numeric foundAt)
Parameters
String string
String to search in.
String characters
The set of characters to look for.
Numeric offset
Offset of the input string to start search from. If positive, search will only look at this number of characters
at the beginning of the string. If negative, the search will not include this number of characters at the end
of the string. If zero, the search will include the whole string.
https://getonetastic.com/docs/OnetasticMacroDocumentation 140/156
11/11/24, 2:09 PM Onetastic Macro Documentation
// 1 2 3 4
// 01234567890123456789012345678901234567890
$string = "a4 b6 c5 4a b6 d5 f6 d7 e4 b6 c2 56 d4 5a"
// ^ ^ ^ ^
// Instances of c, 7 and f are marked with ^
// Not found
String_FindLastOf($string, "abc", 0, $foundAt)
// Returns false, $foundAt is not modified
String_GreaterThan
Returns true if the first string is comes after the second string, false otherwise.
Syntax
Bool String_GreaterThan(
String first,
String second,
Bool ignorecase)
Parameters
String first
First string to compare.
String second
Second string to compare.
Bool ignorecase
Ignores the case of the strings if set to true.
Examples
https://getonetastic.com/docs/OnetasticMacroDocumentation 141/156
11/11/24, 2:09 PM Onetastic Macro Documentation
// case Sensitive
String_GreaterThan("strawberry", "Strawberry", false)
// true
// case Insensitive
String_GreaterThan("strawberry", "Strawberry", true)
// false
String_GreaterThanOrEqualTo
Returns true if the first string is comes after the second string or compares equal, false otherwise.
Syntax
Bool String_GreaterThanOrEqualTo(
String first,
String second,
Bool ignorecase)
Parameters
String first
First string to compare.
String second
Second string to compare.
Bool ignorecase
Ignores the case of the strings if set to true.
Examples
// case Sensitive
String_GreaterThanOrEqualTo("Strawberry", "strawberry", false)
// false
// case Insensitive
String_GreaterThanOrEqualTo("Strawberry", "strawberry", true)
// true
https://getonetastic.com/docs/OnetasticMacroDocumentation 142/156
11/11/24, 2:09 PM Onetastic Macro Documentation
String_Insert
Inserts a string into another string at a specified position and returns the resulting string.
Syntax
String String_Insert(
String string,
String other,
Numeric offset)
Parameters
String string
String to insert into.
String other
String to insert.
Numeric offset
Offset to insert at. If non-negative, the string will be inserted at this number of characters counted from
the beginning of the string. If negative, the string will be inserted at this number of characters counted
from the end of the string.
Examples
// Insert at index 7
String_Insert($string, $insert, 7)
// "the quiJUMPEDck brown fox "
https://getonetastic.com/docs/OnetasticMacroDocumentation 143/156
11/11/24, 2:09 PM Onetastic Macro Documentation
String_Length
Returns the length of the given string.
Syntax
Parameters
String string
String to return the length of.
Examples
String_Length("")
// 0
String_Length("banana")
// 6
String_LessThan
Returns true if the first string is comes before the second string, false otherwise.
Syntax
Bool String_LessThan(
String first,
String second,
Bool ignorecase)
Parameters
String first
First string to compare.
String second
Second string to compare.
Bool ignorecase
Ignores the case of the strings if set to true.
Examples
https://getonetastic.com/docs/OnetasticMacroDocumentation 144/156
11/11/24, 2:09 PM Onetastic Macro Documentation
// case Sensitive
String_LessThan("Strawberry", "strawberry", false)
// true
// case Insensitive
String_LessThan("Strawberry", "strawberry", true)
// false
String_LessThanOrEqualTo
Returns true if the first string is comes before the second string or compares equal, false otherwise.
Syntax
Bool String_LessThanOrEqualTo(
String first,
String second,
Bool ignorecase)
Parameters
String first
First string to compare.
String second
Second string to compare.
Bool ignorecase
Ignores the case of the strings if set to true.
Examples
// case Sensitive
String_LessThanOrEqualTo("strawberry", "Strawberry", false)
// false
// case Insensitive
String_LessThanOrEqualTo("strawberry", "Strawberry", true)
// true
https://getonetastic.com/docs/OnetasticMacroDocumentation 145/156
11/11/24, 2:09 PM Onetastic Macro Documentation
String_Pad
Pads a string to a certain length with another string and returns the resulting string.
Syntax
String String_Pad(
String string,
String padString,
Numeric length,
String padDirection)
Parameters
String string
String to be padded with padString.
String padString
String to pad with.
Numeric length
String will be at this length after padding. If this is smaller than the length of the original string, no padding
happens.
String padDirection
Direction of the padding. Can be "left", "right" or "both".
Examples
String_Repeat
Repeats a string given number of times and returns the resulting string.
https://getonetastic.com/docs/OnetasticMacroDocumentation 146/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Syntax
String String_Repeat(
String string,
Numeric multiplier)
Parameters
String string
String to be repeated.
Numeric multiplier
Number of times to repeat the string.
Examples
String_Repeat("Abc", 5)
// "AbcAbcAbcAbcAbc"
String_Replace
Finds occurences of a search string in the given string and replaces them with a replacement string and returns
the resulting string.
Syntax
String String_Replace(
String string,
Mixed search,
Mixed replacement,
Bool ignorecase,
out Numeric count)
Parameters
String string
String being searched and replaced on.
Mixed search
The value being searched for. This can be a single string or an array of strings. If it is a single string,
replacement should also be a single string and, each occurence of that string is replaced with the
replacement string. If it is an array of strings each value is replaced starting from the first element in the
array. The replacement can be a single string or an array of strings in this case.
https://getonetastic.com/docs/OnetasticMacroDocumentation 147/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Mixed replacement
The value to replace the search string. This can be a single string or an array of strings. If it is a single
string, each occurence of the search string or strings is replaced with the replacement string. If it is an
array of strings each value in the array of search strings is replaced with the corresponding entry in the
replacement array.
Bool ignorecase
Ignores the case of the search string(s) if set to true.
$string = "abcdefghijABCDEFGHIJ"
// Not found
String_Replace($string, "345", "{}", true, $count)
// Returns "abcdefghijABCDEFGHIJ"
// $count is 0
// case Insensitive
String_Replace($string, "def", "{}", true, $count)
// Returns "abc{}ghijABC{}GHIJ"
// $count is 2
// case Sensitive
String_Replace($string, "def", "{}", false, $count)
// Returns "abc{}ghijABCDEFGHIJ"
// $count is 1
https://getonetastic.com/docs/OnetasticMacroDocumentation 148/156
11/11/24, 2:09 PM Onetastic Macro Documentation
String_Reverse
Returns the reverse of a given string.
Syntax
Parameters
String string
String to be reversed.
Examples
String_Reverse("abcdefg")
// "gfedcba"
String_Split
Splits the current string into an array of strings using the given delimiter.
Syntax
Array<String> String_Split(
String string,
String delimiter)
Parameters
https://getonetastic.com/docs/OnetasticMacroDocumentation 149/156
11/11/24, 2:09 PM Onetastic Macro Documentation
String string
String to split into an array.
String delimiter
Delimiter to split the string using. If empty string, the string is split into its characters.
Examples
String_StartsWith
Returns true if the first string starts with the second string, false otherwise.
Syntax
Bool String_StartsWith(
String first,
String second,
Bool ignorecase)
Parameters
String first
First string to compare.
String second
Second string to compare.
Bool ignorecase
Ignores the case of the strings if set to true.
Examples
// case Sensitive
String_StartsWith("The quick brown fox", "the", false)
// false
// case Insensitive
String_StartsWith("The quick brown fox", "the", true)
// true
https://getonetastic.com/docs/OnetasticMacroDocumentation 150/156
11/11/24, 2:09 PM Onetastic Macro Documentation
String_Substring
Returns a part of the given string. The part starts from the 0-based offset and the length of it is count.
Syntax
String String_Substring(
String string,
Numeric offset,
Numeric count)
Parameters
String string
String to return the part of.
Numeric offset
0-based start index of the substring. If non-negative, the substring will start this number of characters
counted from the beginning of the string. If negative, the substring will start this number of characters
counted from the end of the string.
Numeric count
Length of the substring.
Examples
// First 10 characters
$substring = String_Substring("The quick brown fox", 0, 10)
// $substring is "The quick "
// Last 5 characters
$substring = String_Substring("The quick brown fox", -5, 5)
// $substring is "n fox"
String_ToLowerCase
https://getonetastic.com/docs/OnetasticMacroDocumentation 151/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Syntax
Parameters
String string
String to be converted to lowercase.
Examples
String_ToUpperCase
Converts the given string to uppercase.
Syntax
Parameters
String string
String to be converted to uppercase.
Examples
String_Trim
Removes whitespace (or other characters) from the beginning and/or end of a string and returns the resulting
string.
Syntax
String String_Trim(
String string,
https://getonetastic.com/docs/OnetasticMacroDocumentation 152/156
11/11/24, 2:09 PM Onetastic Macro Documentation
String characters,
String trimDirection)
Parameters
String string
String to be trimmed.
String characters
Set of characters to be trimmed. If left empty, following characters will be removed: Space (ASCII 32), Tab
(ASCII 9), New Line (ASCII 10), Carriage Return (ASCII 13), Vertical Tab (ASCII 11).
String trimDirection
Direction of the trim. Can be "left", "right" or "both".
Examples
Window Functions
GetWindows
Window_Close
Window_Create
Window_GetCurrent
Window_NavigateTo
Window_SetCurrent
https://getonetastic.com/docs/OnetasticMacroDocumentation 153/156
11/11/24, 2:09 PM Onetastic Macro Documentation
GetWindows
Returns the set of open OneNote windows .
Syntax
Array<Window> GetWindows()
Parameters
This function has no parameters
Examples
Window_Close
Closes the given OneNote window . If the given window is the current window, one of the other windows will
become the current window. Closing last window may cause unexpected results as it will shut down OneNote and
the notebooks will no longer be accessible to the currently running macro. Accessing a closed window's members
will result in an error.
Syntax
Parameters
Window window
The window to close.
Examples
Window_Create
https://getonetastic.com/docs/OnetasticMacroDocumentation 154/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Creates a new OneNote window . The new window will display the same notebook, section, and page as the
previous current window. The newly created window will become the new current window.
Syntax
Window Window_Create()
Parameters
This function has no parameters
Examples
Window_GetCurrent
Returns the currently open OneNote window .
Syntax
Window Window_GetCurrent()
Parameters
This function has no parameters
Examples
// Navigate the current window to the first page in the current section
$window = Window_GetCurrent()
Window_NavigateTo($window, GetCurrentSection().pages[0])
Window_NavigateTo
Navigates the given window to the provided location. The location can be a hierarchy object, id of a hierarchy
object, or a "onenote:" URL. OneNote may display UI while navigation is under way. This function returns true if
the navigation is successful or false if the location is not found or navigation is cancelled by the user.
Syntax
https://getonetastic.com/docs/OnetasticMacroDocumentation 155/156
11/11/24, 2:09 PM Onetastic Macro Documentation
Bool Window_NavigateTo(
Window window,
Mixed location)
Parameters
Window window
The window to navigate to.
Mixed location
The location to navigate to. Expected types are: Notebook , SectionGroup , Section , Page , or a String for
id of one of those objects or a URL that starts with "onenote:". Navigating to URLs are slower than
navigating with an object or object id.
Examples
// Navigate the current window to the first page in the current section
$window = Window_GetCurrent()
Window_SetCurrent
Makes the given OneNote window the current window.
Syntax
Parameters
Window window
The window to make current.
https://getonetastic.com/docs/OnetasticMacroDocumentation 156/156