When the Windows clipboard has content copied from Evernote, it includes a data object with the format type "ENML Format". For example, if I copy "Chirp Chirp" from a note within Evernote for Windows, I see the following data on the clipboard, associated with the "ENML Format":
<en-clipboard Cookie="6479053"><en-note>Chirp Chirp</en-note></en-clipboard>
I have a C# Windows application in which I want to generate to-do list items and place them on the Windows clipboard, such that they can be pasted into Evernote with checkboxes. (The checkbox element used by Evernote does not exist in HTML, so I can't just put HTML on the clipboard -- it has to be ENML.)
Generating the ENML and placing it on the clipboard is easy enough, but I can't get Evernote to accept it. It seems that Evernote will only accept ENML from the clipboard if it recognizes the "Cookie" number. As an experiment, I tried reusing a "Cookie" value that I captured from a copy action that occurred within Evernote, and with this magic value in place the paste action succeeded. However, in a real-life situation, I have no way of obtaining a "Cookie" number that Evernote will accept.
If I leave the "Cookie" attribute off or put in a random value, pasting into Evernote fails. Only if I set the "Cookie" attribute to a number that was recently generated by Evernote can I get Evernote to paste the ENML I placed on the clipboard. However, if I then exit Evernote and restart it, my pasted content is once again rejected -- the magic number I used before is no longer accepted.
I've tried leaving off the <en-clipboard>
element, and just pasting ENML that starts with the <en-note>
element, but Evernote silently rejects the clipboard payload.
Is there some way to get ENML onto the clipboard from outside Evernote, such that pasting the formatted content into Evernote will actually work? What purpose does the "Cookie" attribute serve?
It turns out that Evernote was not designed to accept ENML from outside applications. The "Cookie" attribute is used to confirm that the "ENML Format" payload was generated by Evernote -- and that it therefore does not need to be validated against the ENML DTD. Ideally, this would mean that ENML that does conform to the DTD would also be accepted, presuming it's valid. However, there's something of a catch-22: Evernote rejects the "ENML Format" clipboard payload if it doesn't have as it's root element... but the element is not defined in the DTD. (Here's the Evernote forum post where a staff person confirmed that pasting ENML from another application wasn't meant to be supported.)
However... I did find a workaround. I was able to paste HTML that includes the to-do checkbox style from ENML, and Evernote translated it into a checkbox, which is ultimately what I was going for. I would prefer to be able to paste proper ENML from another Windows application, but being able to define checkboxes in HTML and have them show up when pasted is an acceptable workaround, for my purpose.
This is an example of HTML for a to-do item as it appears in the clipboard payload:
<div><span style="-en-todo:true;">[]</span>Daily To-Do Item</div>
To put this in context, here's an example of what the entire HTML clipboard payload looks like, including the ridiculous header that's standard for HTML data on the Windows clipboard:
Version:0.9
StartHTML:000000149
EndHTML:000000720
StartFragment:000000251
EndFragment:000000682
StartSelection:000000251
EndSelection:000000682
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body>
<!--StartFragment-->
<div style="-en-clipboard:true;"><span style="font-weight: bold;">Sunday, March 3</span></div><div>Example of a daily reminder</div><div><span style="-en-todo:true;">[]</span>Daily To-Do Item</div><div><span style="font-weight: bold;">Monday, March 4</span></div><div>Example of a daily reminder</div><div><span style="-en-todo:true;">[]</span>Daily To-Do Item</div><div><span style="-en-todo:true;">[]</span>Weekday Item</div>
<!--EndFragment-->
</body>
</html>
If Evernote changes, such that ENML that conforms to the DTD can be generated by another application, placed on the Windows clipboard, and pasted into an existing Evernote note, I would love to hear about it -- and will happily change the accepted answer.