Macro Tutorial

September 20, 2012
An extensive documentation and tutorial is available here. The tutorial below is outdated.

Macros are built using the Macro Editor which can be launched from New Macro or Edit Macros buttons on the ribbon. See this post for more details. Macro Editor looks like below:

Macro editor

Here you can set the name, category and description of the macro and below that you can see the set of commands at your disposal on the left and the macro you are building on the right. You can use the Add and Remove buttons to build your macro. Before diving into all the details here, let's take a look at a simple macro and see how macros are built and how they work. Then we can slowly move into more aspects of macros.

Finding and modifying objects

This macro increases font size of all text on the current page by 1pt. The macro looks like this:

Macro screenshot - Modify Properties

As simple as that. The macro finds text in the current page and modifies its "fontSize" property by adding 1 to it. The blue underlined parts are pieces you can click and change to edit the macro. For instance you can click on "Text" and pick a different object type:

Macro screenshot - Modify Properties

Similarly you can pick the property you want to modify and how you want to modify.

Using conditions to filter objects

When querying for objects on the page, you can make use of conditions which are in the form of:

Macro screenshot - Filter objects

For example if you want to find paragraphs that are edited by "John" and are inside a table which is partially selected, you can do so by:

Macro screenshot - Filter objects

You can combine the "Is under" and "That has" to build more complex conditions. You can add as many of them as you need to specify the objects you are interested in.

Using variables for temporary storage

You can make use of variables, for temporarily storing and manipulating information. For instance if you want to read the text in a table cell and fill the rest of the table with that text, you can temporarily store the text of the first cell in a variable:

Macro screenshot - Variables

This macro stores the "text" property of the first table cell in to a variable named "TextOfFirstCell" and then reuses that to set the text for all the table cells. To add more variables or use existing variables, simply click on the blue underlined part in the Modify line and choose one of the options:

Macro screenshot - Variables

As you can see, you can choose either a property or a variable (existing or new) to modify here.

Using conditions to selectively apply modifications

You may want to apply modifications based on different conditions. The "That has" and "Is under" filters somewhat give you that but once that filter applied and you have the set of objects you can't make further decisions using them. To provide this, you can use If/Else clauses. Let's say you want to highlight text based on author:

Macro screenshot - Conditions

You can build very complex conditional statements using these and selectively apply any modifications. "If" can also evaluate conditions on variables and can use one or more of the following conditional operators, based on the values compared:

Macro screenshot - Conditions

Using indices to store set of values in variables

Macros support storing a set of values in variables as <key, value> pairs. Indices are the way to achieve this. To explain that let's use an example: Copy the values of the first row into the second row in a table.

Macro screenshot - Indices

Here we check the "rowIndex" property of each cell. The first row is where rowIndex is 0, and the second row is where rowIndex is 1. We store text from each cell in the first row in the variable named "Text", indexed by the column index (colIndex property). This way we can store the text from the first row as <colIndex, text> pairs and then reuse it in the next row to set the text for the second row. To add an index to a variable use the "Add index to variable X" option on the variable selector:

Macro screenshot - Indices

This will add the index and you can then choose what to use as an index.

Using constant literal values

You can use constant literal values in the right hand side of That/Modify/If clauses. In fact we already did in most of the above examples. When you click to change the right-hand-side, you will see the list of properties and variables and an option to "Enter literal value". Also if the left-hand-side is a property with known set of values, you will see them there:

Macro screenshot - Literals

Here selection property can be one of "none", "partial" or "all", so you get to choose from one of them. Alternatively you can enter the value manually.

Asking user for input

You can ask user for input during macro execution to modify behavior of the macro. To do so, add a Modify clause and choose a variable for the left-hand-side. For the right hand side choose "Prompt user for value". This will open a dialog to enter details of the user input. For instance if you are building a macro that will search for some text (e.g. Search and replace) you may ask the user for the search term:

Macro screenshot - User Prompts

Macro screenshot - User Prompts

Here you can:

This will prompt the user for input while executing your macro. The above options will result in the following dialog:

Macro screenshot - User Prompts

See how the message and initial value is placed. If you have multiple consecutive user prompts, Onetastic will merge them into a single user dialog. For instance see the following dialog for the Search & Replace macro:

Macro screenshot - User Prompts

Macro screenshot - User Prompts

As you can see 4 Modify clauses are turned into a dialog box with 4 inputs. This also shows different input types: text for "Find what" and "Replace with", dropdown for "Scope", and checkbox for "Match case". You can also see the underlined shortcut keys (like F in Find what), which comes from the & characters right before the corresponding letter. This is standard Windows way of specifying accelerators for labels. Hitting Alt+F will move the cursor to the "Find what" box. Finally, for the first input it is specified that user cannot leave it empty, therefore the OK button is not enabled until user types into it.

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.


Hopefully this gives you some idea about how to build macros with Onetastic. You can also look at existing macros in the Macro Editor by going to Edit Macros dropdown. You can inspect the macro and try to understand how it works.

Update: A new tutorial about inserting text using a macro is available here.

Update 2: You can now upload your macros to Macroland. See more info here.


EricStiles - 2016-06-06
I'm trying to divide a single page in to multiple pages.  I've had no luck at all so I thought I would try writing a macro in OneTastic.  The page that I have is like this.  First a time stamp, then the title, then the body of the page.  And then the cycle repeats it self.  
I'm having issues on how to get started in writing a macro to do this.  Any help would be appreciated.  The following is an example of the single page that I have:

2016-02-16 12:57am UTC

Take Down Side Fence


I took down the side fence on the east side of the house. In prep to get some heavy equipment into the backyard, specifically a bobcat to scrape off 6 to 12 inches of soil around the backyard and the side yard.
I'm not sure how I'm going to do the side yard on the west side of the house, that may have to be done by hand. I'm also not sure when I'm going to rent a bobcat alright gravel dirt dumpster. Hopefully next weekend because I need to get moving especially while the weather is nice and cool. I will not want to do this in the summer time.

2016-02-16 12:58am UTC

Went To Art Gallery With Anil


Went to an Art Gallery in Fallbrook with Anil. It was a watercolor art gallery with the paintings ranging in the several thousands of dollars. It was pretty nice gallery although it did cost money to get in, but Anil paid. Anil also bought lunch at a local Mexican restaurant.

2016-02-16 1:00am UTC

Chris Herencia looked at my drainage problem.


Chris Herencia came over to look at my yard drainage problem. I also mulched all the branches from the avocado tree from last weekend.

2016-02-19 2:47am UTC

Cooking Tilapia Fish


I cooked the Tilapia fish a little different today.
I put Creole powder on the fish, but not too much since it is salty. I then put it in a frying pan with a little oil. I let the fish cook a little.  Then I put water, probably half cup of water maybe more, and then I put the frozen vegetables right alongside the fish and cooked it all together. Once I felt the fish was done and pretty much all the water  had cooked out of it. I then cover the fish with picante sauce added a slight more water to create some more steam put the lid on and cooked it a little more let the picante sauce warm up. When that water had boiled off I then put it in a plate.  It worked out pretty well although I like the salmon much better.

CyberPro - 2016-05-02
I am working on my first attempt to develop a macro that would make a daily task much easier, but I am having problems.
I would like a macro that I could use to create a new page, and add the title of the page to have the month spelled out and the year appended. For example May 2016.
I have tried a couple of different approaches, but I do find that I get confused about the object property "name" and the page property "title". I see a comment that you cannot change the title property with a Onetastic macro. I hope I am incorrect in my understanding.

I create a monthly page that has the month and year, the a sub-page for the week of the month, then a sub-page for each day to enter work notes on things that I am doing. Much like a work journal. I would be very handy to be able to automate those tasks using a single, or multiple Macros.

Could someone please let me know if I am trying to do the impossible?
Knut Draget - 2016-03-10
I want to copy unchecked tasks from a meeting note to a new meeting note.
Is this possible with a Onetastic macro?

Other Posts

Show all posts

DISCLAIMER: The opinions and views expressed in this website are those of the author and do not necessarily state or reflect those of Microsoft.