Sometimes you need to create a page in OneNote and it would be much easier to create it from the command line. A perfect example is from within a batch file or other script. The ability to create OneNote pages from the command line is something that OneNote has never offered before.
Now creating a OneNote page from the command line is simple with OneNoteCLI - The OneNote Command Line Interface. In fact OneNoteCLI can also create sections, delete notes, and append text to existing notes.
This article focuses on simply creating notes. We have other articles that discus creating sections, deleting sections, deleting notes, appending to notes, and importing entire directory trees of text files and images into notebooks.
OneNoteCLI Command Line Options
After unzipping OneNoteCLI to any directory open up a command prompt in the same directory as OneNoteCLI.exe and run it to see a list of options:
C:\temp\OneNoteCLI> OneNoteCLI OneNoteCLI 184.108.40.206 Copyright c 2019 ERROR(S): No verb selected. importfolder Import a folder createnote create a note createsection create a section deletenote delete a note deletesection delete a section appendnote append to an existing note help Display more information on a specific command. version Display version information.
In order to create a new note use the createnote verb.
C:\src\Releases\OneNoteCLI>OneNoteCLI createnote OneNoteCLI 220.127.116.11 Copyright c 2019 ERROR(S): Required option 'n, notebook' is missing. Required option 's, section' is missing. Required option 't, title' is missing. Required option 'b, body' is missing. -n, --notebook Required. (Default: ) Notebook name -s, --section Required. (Default: ) Section name -t, --title Required. (Default: ) New note title -b, --body Required. (Default: ) New note body -w, --wait (Default: false) Wait for keypress --help Display this help screen. --version Display version information.
When you run OneNoteCLI with just the verb it prints a list of required parameters. Notice that the parameters notebook, section, title, and body are required.
- -n - The notebook to create a new page in (must already exist)
- -s - The section to create a new page in (will be created if it doesn't already exist)
- -t - The title of the new page
- -b - The body of the new page
If any of the above parameters require a space in them be sure to surround them with a quote, like this:
- -n "Notebook name"
- -s "Section name"
- -t "Page title"
- -b "This is the body of the note"
Let's say you wanted a new page called First Note in a section called First Section in the notebook called Test Notebook. The command line to create this note is:
OneNoteCLI createnote -n "Test Notebook" -s "First Section" -t "First note" -b "This is the note body"
After running this command, here is the note that was created:
If you specify a section that does not exist the OneNoteCLI will automatically create that section for you. Another example. How about creating a page called Todo in a section called Lists in the notebook called Work:
OneNoteCLI createnote -n "Work" -s "Lists" -t "Todo" -b " - Thank the developer"
The biggest problem that you may encounter is trying to create a note in a section that has been deleted. When you delete a section in OneNote it does not immediately go away. Instead, it goes to the Recycle Bin, where it is still accessible.
If you try to access a section that is currently in the Recycle Bin, OneNoteCLI will throw an error.
The easiest solution to this problem is to empty the OneNote Recycle Bin.
More OneNoteCLI Info
There's more info about OneNoteCLI if you are interested, including how to import entire directories of text and images, delete notes, and append text to existing notes. With OneNoteCLI scripting support for OneNote just got a whole lot easier.