Evernote output format and/or branching subsequent steps in an action

#1

I save a lot of drafts to Evernote. Some are in Markdown format, and some are specifically plain text.

I currently have two actions for this: “Evernote Markdown” and “Evernote Plain Text”. They’re exactly the same, except for the “Template Output Format” in the Evernote step—set, rather obviously, to “text” or “markdown”.

I’d like to have a single action that detects if the first line of the draft contains a markdown H1 and uses the proper output format. Right now I’m doing that with a third action that has this script:

if (/^\#\s/.test(draft.content)) {
	d = Action.find("Evernote Markdown")
} else {
	d = Action.find("Evernote Plain Text")
}

app.queueAction(d, draft)

This works as intended, but is kind of gross, because I see two confirmation notifications up top, and I have to have extra actions hiding in a different group. Can I either:

  1. Set the “Template Output Format” in the Evernote step using a template tag somehow, or otherwise set it from the previous script step?
  2. Have multiple Evernote steps in the action and somehow use the script step to determine which of those gets executed?

If the answer to both of those is “no”, is there a way to execute an action within a script step instead of queueing it up to execute after the current step (and action) completes?

Thanks for your help!

0 Likes

#2

You cannot do either of your specific requests (numbered 1 & 2). There’s no scripting interface to Evernote, mostly because complexity of their native ENML, so you have to use the step, and you cannot conditionally run steps via script at the moment.

A couple of options/notes:

  • You can fix the double-notification problem by disabling notifications on the scripted action you have in front of the queued actions. You don’t really need a notification from it, only from the actual Evernote action.

  • You could use ENML format for the Evernote step, but prep the plain text or Markdown yourself in the script.

For the later, do something like:

var content = ""
if (/^\#\s/.test(draft.content)) {
    // create content as already processed Markdown
    content = draft.processTemplate("%%[[draft]]%%");
} else {
    // convert lines to html blocks
    let lines = draft.content.split("\n");
    let wrappedLines = lines.map(ln => "<div>" + (ln.length > 0 ? ln : "<br/>") + "</div>");
    content = wrappedLines.join("\n");
}
// save content in a tag to use in action step
draft.setTemplateTag("content", content);
// in Evernote action step after this script
// use [[content]] as the content tag.

This might not totally do it. You still might need to encode HTML entities in the plain text version, depending on what’s in your text.

0 Likes

#3

Thanks, Greg. That’s excellent advice. I hadn’t really played with the notification settings, so it turns out your first suggestion gets me what I want—with the bonus that by leaving the notification for the subsequent action turned on, I can see that the proper format was detected. :slight_smile:

Your JS snippet wasn’t in vain, though; I’m working on a different action for the way I’ve started taking meeting notes, and I’ll probably end up using something like that to build my own HTML. I’ve saved this for later—using my Drafts to Evernote action. :slight_smile:

Thanks for the fantastic app. I don’t know why it took me so long to make it a central part of my workflow, but I’m really glad I did.

Chad

2 Likes