CAWT 2.9.1 Reference Manual

::OneNoteTop, Main, Index

The OneNote namespace provides commands to control Microsoft OneNote.

CommandsTop, Main, Index

FindNodeByName [::OneNote]Top, Main, Index

Get a specific node by name.

FindNodeByName domNode nodeType nodeName
domNodeDOM node.
nodeTypeNode type (Notebook, Section, Page).
nodeNameNode name.

Returns the found node or an empty string, if the node could not be found.

See also: FindNotebook, FindSection, FindPage, GetNodeName

proc ::OneNote::FindNodeByName {domNode nodeType nodeName} {

    # Get a specific node by name.
    #
    # domNode  - DOM node.
    # nodeType - Node type (`Notebook`, `Section`, `Page`).
    # nodeName - Node name.
    #
    # Returns the found node or an empty string, if the node could not be found.
    #
    # See also: FindNotebook FindSection FindPage GetNodeName

    set result ""
    if { [OneNote IsNodeType $domNode $nodeType] } {
        if { [OneNote GetNodeName $domNode] eq $nodeName } {
            set result $domNode
        }
        return $result
    }
    if { [$domNode hasChildNodes] } {
        foreach childNode [$domNode childNodes] {
            set result [OneNote::FindNodeByName $childNode $nodeType $nodeName]
            if { $result ne "" } {
                return $result
            }
        }
    }
    return $result
}

FindNotebook [::OneNote]Top, Main, Index

Get a specific notebook by name.

FindNotebook domNode nodeName
domNodeDOM root node as returned by GetDomRoot.
nodeNameNode name.

Returns the found notebook or an empty string, if the notebook could not be found.

See also: FindNodeByName, FindSection, FindPage, GetDomRoot, GetNodeName

proc ::OneNote::FindNotebook {domNode nodeName} {

    # Get a specific notebook by name.
    #
    # domNode  - DOM root node as returned by [GetDomRoot].
    # nodeName - Node name.
    #
    # Returns the found notebook or an empty string, if the notebook could not be found.
    #
    # See also: FindNodeByName FindSection FindPage GetDomRoot GetNodeName

    return [OneNote::FindNodeByName $domNode "Notebook" $nodeName]
}

FindPage [::OneNote]Top, Main, Index

Get a specific page by name.

FindPage domNode nodeName
domNodeDOM node identifying a section.
nodeNameNode name.

Returns the found page or an empty string, if the page could not be found.

See also: FindNodeByName, FindNotebook, FindSection, GetPages, GetNodeName

proc ::OneNote::FindPage {domNode nodeName} {

    # Get a specific page by name.
    #
    # domNode  - DOM node identifying a section.
    # nodeName - Node name.
    #
    # Returns the found page or an empty string, if the page could not be found.
    #
    # See also: FindNodeByName FindNotebook FindSection GetPages GetNodeName

    return [OneNote::FindNodeByName $domNode "Page" $nodeName]
}

FindSection [::OneNote]Top, Main, Index

Get a specific section by name.

FindSection domNode nodeName
domNodeDOM node identifying a notebook.
nodeNameNode name.

Returns the found section or an empty string, if the section could not be found.

See also: FindNodeByName, FindNotebook, FindPage, GetSections, GetNodeName

proc ::OneNote::FindSection {domNode nodeName} {

    # Get a specific section by name.
    #
    # domNode  - DOM node identifying a notebook.
    # nodeName - Node name.
    #
    # Returns the found section or an empty string, if the section could not be found.
    #
    # See also: FindNodeByName FindNotebook FindPage GetSections GetNodeName

    return [OneNote::FindNodeByName $domNode "Section" $nodeName]
}

GetApplicationId [::OneNote]Top, Main, Index

Get the application identifier of a OneNote object.

GetApplicationId oneNoteId
oneNoteIdIdentifier dictionary of a OneNote object.

Returns the application identifier of the OneNote object.

See also: Open, GetDomId

proc ::OneNote::GetApplicationId {oneNoteId} {

    # Get the application identifier of a OneNote object.
    #
    # oneNoteId - Identifier dictionary of a OneNote object.
    #
    # Returns the application identifier of the OneNote object.
    #
    # See also: Open GetDomId

    return [dict get $oneNoteId "appId"]
}

GetDomId [::OneNote]Top, Main, Index

Get the DOM identifier of a OneNote object.

GetDomId oneNoteId
oneNoteIdIdentifier dictionary of a OneNote object.

Returns the DOM identifier of the OneNote object.

See also: Open, GetApplicationId, GetDomRoot

proc ::OneNote::GetDomId {oneNoteId} {

    # Get the DOM identifier of a OneNote object.
    #
    # oneNoteId - Identifier dictionary of a OneNote object.
    #
    # Returns the DOM identifier of the OneNote object.
    #
    # See also: Open GetApplicationId GetDomRoot

    return [dict get $oneNoteId "docId"]
}

GetDomRoot [::OneNote]Top, Main, Index

Get the DOM root of a OneNote object.

GetDomRoot oneNoteId
oneNoteIdIdentifier dictionary of a OneNote object.

Returns the DOM root of the OneNote object.

See also: Open, GetApplicationId, GetDomId

proc ::OneNote::GetDomRoot {oneNoteId} {

    # Get the DOM root of a OneNote object.
    #
    # oneNoteId - Identifier dictionary of a OneNote object.
    #
    # Returns the DOM root of the OneNote object.
    #
    # See also: Open GetApplicationId GetDomId

    return [[dict get $oneNoteId "docId"] documentElement]
}

GetEnum [::OneNote]Top, Main, Index

Get numeric value of an enumeration.

GetEnum enumOrString
enumOrStringEnumeration name

Returns the numeric value of an enumeration.

See also: GetEnumName, GetEnumTypes, GetEnumVal, GetEnumNames

proc ::OneNote::GetEnum {enumOrString} {

    # Get numeric value of an enumeration.
    #
    # enumOrString - Enumeration name
    #
    # Returns the numeric value of an enumeration.
    #
    # See also: GetEnumName GetEnumTypes GetEnumVal GetEnumNames

    set retVal [catch { expr int($enumOrString) } enumInt]
    if { $retVal == 0 } {
        return $enumInt
    } else {
        return [GetEnumVal $enumOrString]
    }
}

GetEnumName [::OneNote]Top, Main, Index

Get name of a given enumeration type and numeric value.

GetEnumName enumType enumVal
enumTypeEnumeration type
enumValEnumeration numeric value.

Returns the list of names of a given enumeration type.

See also: GetEnumNames, GetEnumTypes, GetEnumVal, GetEnum

proc ::OneNote::GetEnumName {enumType enumVal} {

    # Get name of a given enumeration type and numeric value.
    #
    # enumType - Enumeration type
    # enumVal  - Enumeration numeric value.
    #
    # Returns the list of names of a given enumeration type.
    #
    # See also: GetEnumNames GetEnumTypes GetEnumVal GetEnum

    variable enums

    set enumName ""
    if { [info exists enums($enumType)] } {
        foreach { key val } $enums($enumType) {
            if { $val eq $enumVal } {
                set enumName $key
                break
            }
        }
    }
    return $enumName
}

GetEnumNames [::OneNote]Top, Main, Index

Get names of a given enumeration type.

GetEnumNames enumType
enumTypeEnumeration type

Returns the list of names of a given enumeration type.

See also: GetEnumName, GetEnumTypes, GetEnumVal, GetEnum

proc ::OneNote::GetEnumNames {enumType} {

    # Get names of a given enumeration type.
    #
    # enumType - Enumeration type
    #
    # Returns the list of names of a given enumeration type.
    #
    # See also: GetEnumName GetEnumTypes GetEnumVal GetEnum

    variable enums

    if { [info exists enums($enumType)] } {
        foreach { key val } $enums($enumType) {
            lappend nameList $key
        }
        return $nameList
    } else {
        return [list]
    }
}

GetEnumTypes [::OneNote]Top, Main, Index

Get available enumeration types.

GetEnumTypes

Returns the list of available enumeration types.

See also: GetEnumName, GetEnumNames, GetEnumVal, GetEnum

proc ::OneNote::GetEnumTypes {} {

    # Get available enumeration types.
    #
    # Returns the list of available enumeration types.
    #
    # See also: GetEnumName GetEnumNames GetEnumVal GetEnum

    variable enums

    return [lsort -dictionary [array names enums]]
}

GetEnumVal [::OneNote]Top, Main, Index

Get numeric value of an enumeration name.

GetEnumVal enumName
enumNameEnumeration name

Returns the numeric value of an enumeration name.

See also: GetEnumName, GetEnumTypes, GetEnumNames, GetEnum

proc ::OneNote::GetEnumVal {enumName} {

    # Get numeric value of an enumeration name.
    #
    # enumName - Enumeration name
    #
    # Returns the numeric value of an enumeration name.
    #
    # See also: GetEnumName GetEnumTypes GetEnumNames GetEnum

    variable enums

    foreach enumType [GetEnumTypes] {
        set ind [lsearch -exact $enums($enumType) $enumName]
        if { $ind >= 0 } {
            return [lindex $enums($enumType) [expr { $ind + 1 }]]
        }
    }
    return ""
}

GetExtString [::OneNote]Top, Main, Index

Return the default extension of a OneNote file.

GetExtString oneNoteId
oneNoteIdIdentifier dictionary of a OneNote object.

Returns the default extension of a OneNote file.

See also: Open, GetVersion

proc ::OneNote::GetExtString {oneNoteId} {

    # Return the default extension of a OneNote file.
    #
    # oneNoteId - Identifier dictionary of a OneNote object.
    #
    # Returns the default extension of a OneNote file.
    #
    # See also: Open GetVersion

    # oneNoteId is only needed, so we are sure, that oneNoteVersion is initialized.
    # Note: Currently not needed, but kept to be conformant to other Cawt modules.

    variable oneNoteVersion

    return ".one"
}

GetLastModified [::OneNote]Top, Main, Index

Get nodes with specific modification date.

GetLastModified domNode ?compareDate? ?nodeType? ?notebookName?
domNodeDOM node.
compareDateDate in seconds (as returned by clock seconds). Optional, default 0.
nodeTypeNode type (any, Notebook, Section, Page). Optional, default any.
notebookNameNotebook name. Optional, default "".

Returns found nodes as list.

See also: FindNotebook, GetDomRoot

proc ::OneNote::GetLastModified {domNode {compareDate 0} {nodeType any} {notebookName {}}} {

    # Get nodes with specific modification date.
    #
    # domNode      - DOM node.
    # compareDate  - Date in seconds (as returned by `clock seconds`).
    # nodeType     - Node type (`any`, `Notebook`, `Section`, `Page`).
    # notebookName - Notebook name.
    #
    # Returns found nodes as list.
    #
    # See also: FindNotebook GetDomRoot

    variable sModifiedList

    catch { unset sModifiedList }
    set modifiedList [list]
    OneNote::_GetLastModifiedRecursive $domNode $compareDate $nodeType $notebookName
    foreach date [lsort -integer -decreasing [array names sModifiedList]] {
        foreach entry $sModifiedList($date) {
            lappend modifiedList $entry
        }
    }
    return $modifiedList
}

GetNodeAttribute [::OneNote]Top, Main, Index

Get attribute value of a DOM node.

GetNodeAttribute domNode attrName
domNodeDOM node.
attrNameAttribute name.

Returns attribute value as string.

See also: GetNodeName, GetNodeHyperLink

proc ::OneNote::GetNodeAttribute {domNode attrName} {

    # Get attribute value of a DOM node.
    #
    # domNode  - DOM node.
    # attrName - Attribute name.
    #
    # Returns attribute value as string.
    #
    # See also: GetNodeName GetNodeHyperLink

    set attrValue ""
    if { [$domNode hasAttribute $attrName] } {
        set attrValue [$domNode getAttribute $attrName]
    }
    return $attrValue
}

GetNodeHyperLink [::OneNote]Top, Main, Index

Get hyperlink to OneNote node.

GetNodeHyperLink oneNoteId domNode
oneNoteIdIdentifier dictionary of a OneNote object.
domNodeDOM node.

Returns hyperlink as string.

See also: Open, GetNodeAttribute, GetNodeName

proc ::OneNote::GetNodeHyperLink {oneNoteId domNode} {

    # Get hyperlink to OneNote node.
    #
    # oneNoteId - Identifier dictionary of a OneNote object.
    # domNode   - DOM node.
    #
    # Returns hyperlink as string.
    #
    # See also: Open GetNodeAttribute GetNodeName

    set objId [OneNote GetNodeAttribute $domNode "ID"]
    set appId [OneNote GetApplicationId $oneNoteId]
    $appId -call GetHyperlinkToObject $objId "" xmlOut
    return [twapi::variant_value $xmlOut 0 0 0]
}

GetNodeName [::OneNote]Top, Main, Index

Get value of node attribute name.

GetNodeName domNode
domNodeDOM node.

Returns attribute value as string.

See also: GetNodeAttribute, GetNodeHyperLink

proc ::OneNote::GetNodeName {domNode} {

    # Get value of node attribute `name`.
    #
    # domNode - DOM node.
    #
    # Returns attribute value as string.
    #
    # See also: GetNodeAttribute GetNodeHyperLink

    return [OneNote GetNodeAttribute $domNode "name"]
}

GetNodesByType [::OneNote]Top, Main, Index

Get nodes of specific type.

GetNodesByType domNode nodeType
domNodeDOM node.
nodeTypeNode type (Notebook, Section, Page).

Returns the found nodes as a list.

See also: GetNotebooks, GetSections, GetPages, GetNodeType

proc ::OneNote::GetNodesByType {domNode nodeType} {

    # Get nodes of specific type.
    #
    # domNode  - DOM node.
    # nodeType - Node type (`Notebook`, `Section`, `Page`).
    #
    # Returns the found nodes as a list.
    #
    # See also: GetNotebooks GetSections GetPages GetNodeType

    set resultList [list]
    if { [OneNote IsNodeType $domNode $nodeType] } {
        return $domNode
    }
    if {[$domNode hasChildNodes]} {
        foreach childNode [$domNode childNodes] {
            set result [OneNote::GetNodesByType $childNode $nodeType]
            if { [llength $result] > 0 } {
                lappend resultList {*}$result
            }
        }
    }
    return $resultList
}

GetNodeType [::OneNote]Top, Main, Index

Get type of a DOM node.

GetNodeType domNode
domNodeDOM node.

Returns node type as string. Possible values: Notebook, Section, Page.

See also: IsNodeType, GetNodesByType

proc ::OneNote::GetNodeType {domNode} {

    # Get type of a DOM node.
    #
    # domNode  - DOM node.
    #
    # Returns node type as string.
    # Possible values: `Notebook`, `Section`, `Page`.
    #
    # See also: IsNodeType GetNodesByType

    set nodeType [$domNode nodeName]
    return [lindex [split $nodeType ":"] 1]
}

GetNotebooks [::OneNote]Top, Main, Index

Get the notebooks of a OneNote object.

GetNotebooks domNode
domNodeDOM root node as returned by GetDomRoot.

Returns the notebooks of the OneNote object as list.

See also: GetNodesByType, GetSections, GetPages, GetDomRoot, GetNodeType

proc ::OneNote::GetNotebooks {domNode} {

    # Get the notebooks of a OneNote object.
    #
    # domNode - DOM root node as returned by GetDomRoot.
    #
    # Returns the notebooks of the OneNote object as list.
    #
    # See also: GetNodesByType GetSections GetPages GetDomRoot GetNodeType

    return [OneNote::GetNodesByType $domNode "Notebook"]
}

GetPageContent [::OneNote]Top, Main, Index

Get page content as XML.

GetPageContent oneNoteId domNode
oneNoteIdIdentifier dictionary of a OneNote object.
domNodeDOM node of a page.

See also: Open, PrintPage

proc ::OneNote::GetPageContent {oneNoteId domNode} {

    # Get page content as XML.
    #
    # oneNoteId - Identifier dictionary of a OneNote object.
    # domNode   - DOM node of a page.
    #
    # See also: Open PrintPage

    set pageId [OneNote GetNodeAttribute $domNode "ID"]
    set appId  [OneNote GetApplicationId $oneNoteId]
    $appId -call GetPageContent $pageId xmlOut
    set pageXml [twapi::variant_value $xmlOut 0 0 0]
    set pageDoc [dom parse $pageXml]
    return $pageDoc
}

GetPages [::OneNote]Top, Main, Index

Get the pages of a OneNote section.

GetPages domNode
domNodeDOM node identifying a section.

Return the pages of the OneNote section as list.

See also: GetNodesByType, GetSections, GetPages, FindSection, GetNodeType

proc ::OneNote::GetPages {domNode} {

    # Get the pages of a OneNote section.
    #
    # domNode - DOM node identifying a section.
    #
    # Return the pages of the OneNote section as list.
    #
    # See also: GetNodesByType GetSections GetPages FindSection GetNodeType

    return [OneNote::GetNodesByType $domNode "Page"]
}

GetSections [::OneNote]Top, Main, Index

Get the sections of a OneNote notebook.

GetSections domNode
domNodeDOM node identifying a notebook.

Returns the sections of the OneNote notebook as list.

See also: GetNodesByType, GetNotebooks, GetPages, FindNotebook, GetNodeType

proc ::OneNote::GetSections {domNode} {

    # Get the sections of a OneNote notebook.
    #
    # domNode - DOM node identifying a notebook.
    #
    # Returns the sections of the OneNote notebook as list.
    #
    # See also: GetNodesByType GetNotebooks GetPages FindNotebook GetNodeType

    return [OneNote::GetNodesByType $domNode "Section"]
}

GetVersion [::OneNote]Top, Main, Index

Return the version of a OneNote application.

GetVersion oneNoteId ?useString?
oneNoteIdIdentifier dictionary of a OneNote object.
useStringIf set to true, return the version name (ex. OneNote 2010). Otherwise return the version number (ex. 12.0). Optional, default false.

Both version name and version number are returned as strings. Version number is in a format, so that it can be evaluated as a floating point number.

Returns the version of a OneNote application.

See also: Open, GetExtString

proc ::OneNote::GetVersion {oneNoteId {useString false}} {

    # Return the version of a OneNote application.
    #
    # oneNoteId - Identifier dictionary of a OneNote object.
    # useString - If set to true, return the version name (ex. `OneNote 2010`).
    #             Otherwise return the version number (ex. `12.0`).
    #
    # Both version name and version number are returned as strings.
    # Version number is in a format, so that it can be evaluated as a
    # floating point number.
    #
    # Returns the version of a OneNote application.
    #
    # See also: Open GetExtString

    variable oneNoteVersion

    array set map {
        "12.0" "OneNote 2007"
        "14.0" "OneNote 2010"
        "15.0" "OneNote 2013"
        "16.0" "OneNote 2016"
    }

    if { $useString } {
        if { [info exists map($oneNoteVersion)] } {
            return $map($oneNoteVersion)
        } else {
            return "Unknown OneNote version $oneNoteVersion"
        }
    } else {
        return $oneNoteVersion
    }
}

IsNodeType [::OneNote]Top, Main, Index

Check, if node is of specific type.

IsNodeType domNode nodeType
domNodeDOM node.
nodeTypeNode type (Notebook, Section, Page).

Returns true, if node is of specified type. Otherwise false.

See also: GetNodeType, GetNodesByType

proc ::OneNote::IsNodeType {domNode nodeType} {

    # Check, if node is of specific type.
    #
    # domNode  - DOM node.
    # nodeType - Node type (`Notebook`, `Section`, `Page`).
    #
    # Returns true, if node is of specified type. Otherwise false.
    #
    # See also: GetNodeType GetNodesByType

    if { $nodeType eq "any" || [OneNote GetNodeType $domNode] eq $nodeType } {
        return true
    } else {
        return false
    }
}

Open [::OneNote]Top, Main, Index

Open a OneNote instance.

Open

The identifier is a dictionary containing 2 elements:

Key appIdThe application identifier.
Key docIdThe DOM node identifier.

Returns the identifier of the OneNote instance.

See also: Quit, GetApplicationId, GetDomId

proc ::OneNote::Open {} {

    # Open a OneNote instance.
    #
    # Returns the identifier of the OneNote instance.
    #
    # The identifier is a dictionary containing 2 elements:
    # Key appId - The application identifier.
    # Key docId - The DOM node identifier.
    #
    # See also: Quit GetApplicationId GetDomId

    variable oneNoteVersion
    variable oneNoteAppName

    if { ! [Cawt HavePkg "tdom"] } {
        error "Cannot use $oneNoteAppName. No tDOM extension available."
    }
    foreach version { 10 11 12 13 14 15 16 17 18 19 20 } {
        set catchVal [catch { twapi::comobj $oneNoteAppName.$version } appId]
        if { ! $catchVal } {
            set catchVal [catch { $appId GetHierarchy "" $::OneNote::hsSelf str } retVal]
            if { ! $catchVal } {
                # puts "Using $oneNoteAppName.$version"
                set oneNoteVersion "$version.0"
                set hierarchyXml [OneNote::_GetHierarchy $appId "" $::OneNote::hsPages]
                set doc [dom parse $hierarchyXml]
                dict set oneNoteId "appId" $appId
                dict set oneNoteId "docId" $doc
                return $oneNoteId
            }
        }
    }
    error "Cannot open $oneNoteAppName application."
}

PrintPage [::OneNote]Top, Main, Index

Print page content as XML to standard output.

PrintPage oneNoteId domNode
oneNoteIdIdentifier dictionary of a OneNote object.
domNodeDOM node of a page.

Returns no value.

See also: GetPageContent

proc ::OneNote::PrintPage {oneNoteId domNode} {

    # Print page content as XML to standard output.
    #
    # oneNoteId - Identifier dictionary of a OneNote object.
    # domNode   - DOM node of a page.
    #
    # Returns no value.
    #
    # See also: GetPageContent

    set pageDomDoc [OneNote GetPageContent $oneNoteId $domNode]
    set pageRoot   [$pageDomDoc documentElement]
    puts [$pageRoot asXML]
}

Quit [::OneNote]Top, Main, Index

Quit a OneNote instance.

Quit oneNoteId
oneNoteIdIdentifier dictionary of a OneNote object.

Returns no value.

See also: Open

proc ::OneNote::Quit {oneNoteId} {

    # Quit a OneNote instance.
    #
    # oneNoteId - Identifier dictionary of a OneNote object.
    #
    # Returns no value.
    #
    # See also: Open
}