Evernote AppleScript

Hello,

I am trying to modify this script to mimic an iOS action for Evernote that uses Line 1 for the note title, Line 2 for notebook, Line 3 for tags, and Line 5 and beyond as the body of the note.

I have no scripting knowledge, and by trial and error I got as far as this:

let method = "execute";
let script = `on execute(titleText, tagList, htmlContent)
	tell application id "com.evernote.evernote"
		set theNote to create note with text titleText title titleText tags tagList notebook notebook
		set HTML content of theNote to htmlContent
	end tell
end execute`;

let title = draft.processTemplate("[[line|1]]");
let notebook = draft.processTemplate("[[line|2]]");
let tags = draft.processTemplate("[[line|3]]");
let html = draft.processTemplate(`%%[[draft]]%%`);

let runner = AppleScript.create(script);
if (runner.execute(method, [title, tags, notebook, html])) {
	//
}
else {
	console.log(runner.lastError);
	context.fail();
}

This is able to create a note in Evernote that uses line 3 of the draft as tags. My questions are:

  • Line 2 does not translate into the notebook of the note in Evernote. I think I got the variable for notebook wrong in set theNote to create note with text titleText title titleText tags tagList notebook notebook. What should I put instead?

  • How can I make [[Line|5…]] as the body of the note (in Evernote)? I tried substituting %%[[draft]]%% with [[Line|5..]] but it didn’t work

Thanks in advance!

1 Like

I was under the impression Evernote dropped AppleScript support in their app a couple of years ago with their major upgrade. I just looked, and I’m not seeing any AppleScript dictionary for the Evernote app.

Are you using an old version or something?

Yes, I’m using Evernote Legacy.

This page states that:

For a full description of each command and its syntax, view the Evernote AppleScript dictionary in Apple’s Script Editor application. The Script Editor can be found in /Applications/AppleScript/Script/Editor.app. To open the Evernote dictionary, choose "File > Open Dictionary… " and then select Evernote from the displayed list of applications.

Interesting. I didn’t know they still let you download that version…though it appears it comes with a caveat that it’s not supported or updated…so, I’d be ready for it to just stop working one day.

If you are fine with that, notes on your script:

The execute method does not take a notebook param, it takes three params, and you are passing in four when you call it with the runner. I think you need to modify the parameter signature to something like the below:

let script = `on execute(titleText, tagList, theNotebook, htmlContent)
	tell application id "com.evernote.evernote"
		set theNote to create note with text titleText title titleText tags tagList notebook theNotebook
		set HTML content of theNote to htmlContent
	end tell
end execute`;

I don’t know if that works, I don’t have the Evernote app to look at, it’s possible it wants a notebook object, not just the name of a notebook. :man_shrugging:

As for getting the fifth line on, %%[[line|5..]]%% should work. The %% part is converting Markdown to HTML, which is important since you are setting the HTML content of the note, not plain text, that that ensures it’s encoded properly.

Thank you! That worked.

For reference for other readers, this is what I use:

let method = "execute";
let script = `on execute(titleText, tagList, theNotebook, htmlContent)
	tell application id "com.evernote.evernote"
		set theNote to create note with text titleText title titleText tags tagList notebook theNotebook
		set HTML content of theNote to htmlContent
	end tell
end execute`;

let title = draft.processTemplate("[[line|1]]");
let notebook = draft.processTemplate("[[line|2]]");
let tags = draft.processTemplate("[[line|3]]");
let html = draft.processTemplate(`%%[[line|5..]]%%`);

let runner = AppleScript.create(script);
if (runner.execute(method, [title, tags, notebook, html])) {
	//
}
else {
	console.log(runner.lastError);
	context.fail();
}
1 Like