Onetastic Macro Documentation >
>
Accessing the clipboard Accessing the clipboard
With macros, you can read from and write to system clipboard and access any plain
text, HTML or image content in the clipboard. This can allow you to copy content from
OneNote in various formats as well as paste content into OneNote programmatically.
Following functions facilitate these:
- Clipboard_Get
Returns information from the clipboard for the specified format.
- Clipboard_Set
Puts information into the clipboard.
- Clipboard_Query
Returns whether the clipboard contains the specified format or not.
HTML Objects
Applications often use HTML as the format for transferring rich content through Clipboard or
other mediums. To help with this you can now export content from OneNote into HTML format as
well as import HTML content into OneNote. See details of following function and object
type for more information:
- GetFormattedObjectContent
Returns the contents of an object in either plain
text or HTML format. This can be useful to put the content into clipboard using Clipboard_Set,
or process it further.
- HtmlBlock
An object type that represents a block of HTML to be inserted into
a OneNote Outline or Cell.
Examples
Clipboard_Set and GetFormattedObjectContent
Copied!
Clipboard_Set("plain", "Some text")
Clipboard_Set("html", "Some <b>Text</b>")
Clipboard_Set(Array("plain", "html"), Array("Some text", "Some <b>Text</b>"))
$outline = GetCurrentPage().outlines[0]
Clipboard_Set("html", GetFormattedObjectContent($outline, "html"))
$image = GetCurrentPage().images[0]
Clipboard_Set("image", $image.data)
Clipboard_Query, Clipboard_Get, and HtmlBlock
Copied!
$page = GetCurrentPage()
if (Clipboard_Query("plain"))
$page.title.paragraph.text = Clipboard_Get("plain")
if (Clipboard_Query("html"))
$htmlBlock = InsertObject($page.outlines[0], "HtmlBlock", -1)
$htmlBlock.value = Clipboard_Get("html")
if (Clipboard_Query("image"))
$image = InsertObject($page, "Image", -1)
$image.data = Clipboard_Get("image")
|