Tutorial

Getting Started with Macros

Macro Editor

User Interface

Editing Macro Statements

Expression Editor

How To

Using variables

Finding and modifying objects

Creating new page content

Asking for user input

Sorting objects

Macro Logging

Sample Macros

Concepts

Expressions

Objects

Properties

Variables

Data Types

Arrays

Functions

Literals

Operators

Comments

Macro Logging

When you run your macro, if it doesn't seem to be doing what you expect it to be doing, there is a way to generate logs from the execution to investigate the cause. To do so, go to the Settings and check Enable Macro Logging in the ribbon and re-run your macro. This will generate a macrolog.txt file under %appdata%\Onetastic. You can see what operations took place and what the values of variables and properties were in the log file.

Below is a log of an actual run of the Search & Replace macro:

Running Macro "Search & Replace"
------------------------------------------------------------------------
// Show the dialog box
------------------------------------------------------------------------
$dialog_box = DialogBox_Create("")
	Evaluating expression: DialogBox_Create("")
		Value: Object of type DialogBox
	New Value: Object of type DialogBox
	Evaluating expression: ($dialog_box = DialogBox_Create(""))
		Value: Object of type DialogBox
------------------------------------------------------------------------
DialogBox_AddTextBox($dialog_box, "&Find what", $Search, "", false)
	Evaluating expression: $dialog_box
		Value: Object of type DialogBox
	Evaluating expression: $Search
		Value: <empty>
	Evaluating expression: DialogBox_AddTextBox($dialog_box, "&Find what", $Search, "", false)
		Value: <empty>
------------------------------------------------------------------------
DialogBox_AddTextBox($dialog_box, "&Replace with", $Replace, "", true)
	Evaluating expression: $dialog_box
		Value: Object of type DialogBox
	Evaluating expression: $Replace
		Value: <empty>
	Evaluating expression: DialogBox_AddTextBox($dialog_box, "&Replace with", $Replace, "", true)
		Value: <empty>
------------------------------------------------------------------------
DialogBox_AddDropDown($dialog_box, "&Scope", $Scope, "", Array("Current page", "Selection", "Current section", "Current notebook", "All notebooks"))
	Evaluating expression: $dialog_box
		Value: Object of type DialogBox
	Evaluating expression: $Scope
		Value: <empty>
	Evaluating expression: Array("Current page", "Selection", "Current section", "Current notebook", "All notebooks")
		Value: Array of size (5):
			[0]: Current page (string)
			[1]: Selection (string)
			[2]: Current section (string)
			[3]: Current notebook (string)
			[4]: All notebooks (string)
	Evaluating expression: DialogBox_AddDropDown($dialog_box, "&Scope", $Scope, "", Array("Current page", "Selection", "Current section", "Current notebook", "All notebooks"))
		Value: <empty>
------------------------------------------------------------------------
DialogBox_AddCheckBox($dialog_box, "Match &case", $MatchCase, false)
	Evaluating expression: $dialog_box
		Value: Object of type DialogBox
	Evaluating expression: $MatchCase
		Value: <empty>
	Evaluating expression: DialogBox_AddCheckBox($dialog_box, "Match &case", $MatchCase, false)
		Value: <empty>
------------------------------------------------------------------------
DialogBox_Show($dialog_box)
	Evaluating expression: $dialog_box
		Value: Object of type DialogBox
	Evaluating expression: DialogBox_Show($dialog_box)
		Value: <empty>
------------------------------------------------------------------------
// Find matching text objects
------------------------------------------------------------------------
If ($Scope == "Selection")
	Evaluating expression: $Scope
		Value: Current page (string)
	Evaluating expression: ($Scope == "Selection")
		Value: false (boolean)
	Condition evaluated to false
------------------------------------------------------------------------
If ($Scope == "Current page")
	Evaluating expression: $Scope
		Value: Current page (string)
	Evaluating expression: ($Scope == "Current page")
		Value: true (boolean)
	Condition evaluated to true
------------------------------------------------------------------------
$Objects = QueryText(GetCurrentPage(), $Search, !$MatchCase)
	Retrieving page 'Title'
	Evaluating expression: GetCurrentPage()
		Value: Object of type Page
	Evaluating expression: $Search
		Value: the (string)
	Evaluating expression: $MatchCase
		Value: false (string)
	Evaluating expression: !$MatchCase
		Value: true (boolean)
	Querying each Text in Object of type Page
	Retrieving page contents under Object of type Page
	Retrieving contents for page  'Title'
		Found 0 pieces of text with value 'the'
		Found 0 pieces of text with value 'the'
		Found 0 pieces of text with value 'the'
		Found 0 pieces of text with value 'the'
		Found 0 pieces of text with value 'the'
		Found 1 pieces of text with value 'the'
		Found 0 pieces of text with value 'the'
		Found 0 pieces of text with value 'the'
		Found 0 pieces of text with value 'the'
		Found 1 pieces of text with value 'the'
		Found 0 pieces of text with value 'the'
		Found 0 pieces of text with value 'the'
		Found 0 pieces of text with value 'the'
		Found 0 pieces of text with value 'the'
		Found 2 pieces of text with value 'the'
	Evaluating expression: QueryText(GetCurrentPage(), $Search, !$MatchCase)
		Value: Array of size (4):
			[0]: Object of type Text
			[1]: Object of type Text
			[2]: Object of type Text
			[3]: Object of type Text
	New Value: Array of size (4):
			[0]: Object of type Text
			[1]: Object of type Text
			[2]: Object of type Text
			[3]: Object of type Text
	Evaluating expression: ($Objects = QueryText(GetCurrentPage(), $Search, !$MatchCase))
		Value: Array of size (4):
			[0]: Object of type Text
			[1]: Object of type Text
			[2]: Object of type Text
			[3]: Object of type Text
------------------------------------------------------------------------
// Replace found objects
------------------------------------------------------------------------
ForEach Text in $Objects
	Evaluating expression: $Objects
		Value: Array of size (4):
			[0]: Object of type Text
			[1]: Object of type Text
			[2]: Object of type Text
			[3]: Object of type Text
------------------------------------------------------------------------
$Text.value = $Replace
	Evaluating expression: $Replace
		Value: this (string)
Modifying property(value) = The (string) -- = -- this (string)
	New value: this (string)
	Evaluating expression: ($Text.value = $Replace)
		Value: this (string)
------------------------------------------------------------------------
$Text.value = $Replace
	Evaluating expression: $Replace
		Value: this (string)
Modifying property(value) = the (string) -- = -- this (string)
	New value: this (string)
	Evaluating expression: ($Text.value = $Replace)
		Value: this (string)
------------------------------------------------------------------------
$Text.value = $Replace
	Evaluating expression: $Replace
		Value: this (string)
Modifying property(value) = the (string) -- = -- this (string)
	New value: this (string)
	Evaluating expression: ($Text.value = $Replace)
		Value: this (string)
------------------------------------------------------------------------
$Text.value = $Replace
	Evaluating expression: $Replace
		Value: this (string)
Modifying property(value) = the (string) -- = -- this (string)
	New value: this (string)
	Evaluating expression: ($Text.value = $Replace)
		Value: this (string)
------------------------------------------------------------------------
// Report the result
------------------------------------------------------------------------
If (($Count = Array_Length($Objects)) == 0)
	Evaluating expression: $Objects
		Value: Array of size (4):
			[0]: Object of type Text
			[1]: Object of type Text
			[2]: Object of type Text
			[3]: Object of type Text
	Evaluating expression: Array_Length($Objects)
		Value: 4 (unsigned integer)
	New Value: 4 (unsigned integer)
	Evaluating expression: ($Count = Array_Length($Objects))
		Value: 4 (unsigned integer)
	Evaluating expression: (($Count = Array_Length($Objects)) == 0)
		Value: false (boolean)
	Condition evaluated to false
------------------------------------------------------------------------
$Message = ((($Count + " instances of \"") + $Search) + "\" is replaced")
	Evaluating expression: $Count
		Value: 4 (unsigned integer)
	Evaluating expression: ($Count + " instances of \"")
		Value: 4 instances of " (string)
	Evaluating expression: $Search
		Value: the (string)
	Evaluating expression: (($Count + " instances of \"") + $Search)
		Value: 4 instances of "the (string)
	Evaluating expression: ((($Count + " instances of \"") + $Search) + "\" is replaced")
		Value: 4 instances of "the" is replaced (string)
	New Value: 4 instances of "the" is replaced (string)
	Evaluating expression: ($Message = ((($Count + " instances of \"") + $Search) + "\" is replaced"))
		Value: 4 instances of "the" is replaced (string)
------------------------------------------------------------------------
DialogBox_Show(DialogBox_Create($Message))
	Evaluating expression: $Message
		Value: 4 instances of "the" is replaced (string)
	Evaluating expression: DialogBox_Create($Message)
		Value: Object of type DialogBox
	Evaluating expression: DialogBox_Show(DialogBox_Create($Message))
		Value: <empty>
1 pages are modified. They will now be saved to OneNote

Reference

Statements

ForEach

If

Else

While

Expression

Comment

Break

Continue

Hierarchy Objects

NotebookRoot

Notebook

SectionGroup

Section

Page

Page Objects

Title

Outline

Table

Column

Row

Cell

Paragraph

Text

Image

EmbeddedFile

Tag

Other Objects

DialogBox

Functions

Array Functions

Date/Time Functions

Dialog Box Functions

Macro Execution Functions

Object Functions

String Functions