You can use the
not operator to flip the current state of the
note expanded property of a content panel tree node.
Code:
tell application id "OFOC"
tell default document
tell content of front document window
set lstTaskNode to selected trees where class of value is task or class of value is inbox task
repeat with oTaskNode in lstTaskNode
tell oTaskNode to set note expanded to (not note expanded)
end repeat
end tell
end tell
end tell