« Macs, Androids and Micro SD cards just don't mix | Main | Embracing Facebook »

Evernote Note Templates - Show me the new note

I had a comment recently relating to my post about a templating system for Evernote. The approach is that on Windows a system tray/notification area menu utility is used to call a batch script with some parameters and this uses a command line tool for Evernote (ENScript) to create a new note based on a template file based on an exported and amended note in Evernote. The comment noted that the new note that was created was not selected automatically in Evernote and asked if there was a solution. Well, there is....

So this had never really been an issue for me as for my template notes I have saved searches that are available within a click, but it seems a bit of a no brainer to automate this step. So thanks to 'Ryan' for picking this up.

Again the solution is through ENSCRIPT.EXE. As well as an 'importnotes' feature, there is also a 'shownotes' feature that takes a standard Evernote query string and uses that to tell Evernote what to display. So the trick was just to pass Evernote a query string that translates as "display the last note created".

To select the last created note I store the timestamp when the script first starts to run. It then creates the note. Finally the timestamp is used to build a query that tells Evernote to display any note created since the script started running and is in the notebook we've just created the note in.

This query is not infallible since if any other notes are created after the script begins to run, they are also displayed in Evernote. The one additional step I can easily take is to specify the notebook as well which would eliminate any notes created afterwards in other notebooks. If you want to be absolutely accurate the you could tailor it to pick out additional information from the template note being imported. At the end of the day this is just a crude batch file solution.

The amended code for the import batch file is shown below. If you want more detail about how to use the script, then it's definitely worth checking out my previous Evernote templates for Windows post. I'd also recommend brushing up on creating searches (a.k.a. a query string) in Evernote from section C of the Evernote API documentation.

@echo off
set QueryString=created:%TimeStamp%
set ENscriptLocation="C:\Data\Applications\Evernote 3.5\ENScript.exe"
set EvernoteDatabaseLocation="C:\Data\Evernote Data\Databases\evernotedatabase.exb"
set DefaultNotebook="_Inbox"

if x%2==x goto NOTE_ONLY

set QueryString=notebook:%DefaultNotebook% %QueryString%
%ENscriptLocation% importNotes /s %1 /n %DefaultNotebook% /d %EvernoteDatabaseLocation%
%ENscriptLocation% showNotes /q "%QueryString%" /d %EvernoteDatabaseLocation%
goto :EOF

set QueryString=notebook:%2 %QueryString%
%ENscriptLocation% importNotes /s %1 /n %2 /d %EvernoteDatabaseLocation%
%ENscriptLocation% showNotes /q "%QueryString%" /d %EvernoteDatabaseLocation%
goto :EOF

for /f "tokens=1,2,3 delims=:" %%a in ("%time%") do ^
set hour=%%a& ^
set minute=%%b& ^
set second=%%c

for /f "tokens=1,2 delims=." %%a in ("%second%") do ^
set second=%%a& ^
set remainder=%%b

for /f "tokens=1,2,3 delims=/" %%a in ("%date%") do ^
set day=%%a& ^
set month=%%b& ^
set year=%%c

set TimeStamp=%year%%Month%%day%T%hour%%minute%%second%
goto :EOF

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (4)


Just tried to get this to work but it fails with the message:

File does not exists: "/n"

Doing a bit of debug it appears that it is going into :NOTE_AND_NOTEBOOK section but %2 is empty.

Unlike the original script this one does not seem to create the XML files. Is this one supposed to be combined with the original one?



May 16, 2011 | Unregistered CommenterNeil

The script should work stand alone without you trying to incorporate any code from the previous script. The script in this post is just a modification of the script in the previous post. The original script doesn't create any XML files. You need to create the file to be used as a template (by exporting a note in ENML format from Evernote) and this is then passed as the first parameter (for use with ENSCRIPT.EXE /S) to the script.

If no second parameter (i.e. the notebook) is being passed then the section labelled START *should* goto the NOTE_AND_NOTEBOOK section. If you're ending up in the NOTE_AND_NOTEBOOK section, then the batch script doesn't seem to think %2 is 'empty' ... it may just contain something you can't see, like a space or carriage return character.

Just in case you aren't already, when you pass the parameters try enclosing them in double quotes. If there are any spaces in the parameters this should make them appear as the right number of parameters.

To find out exactly what's going on, you might want to add the following in after line 09.

echo @%2@ > c:\debug.txt

This should output exactly what is in the second paramater between a pair of at symbols. The output will be stored in the file debug.txt on the root of the C drive. Open the file in a text editor, or ideally a hex editor and take a look at what (if anything is between) the two at symbols. This will hopefully explain why the conditional statement in the START section is seemingly sending you off to the wrong section (or the right section with the wrong data).

If you get stuck, e-mail me the content and location of your script file and the parameters that you're passing to it and I'll see if I can work out what's going on.

NB: My aim with using batch scripts was to keep things as simple as possible. However Windows batch files but they aren't alway the easiest of things to debug (particularly when using lots of variables and parameters). I did put together a VBS version of the previous script a while back with extra debugging and logging for someone, so if things really get tricky I can always amend and post that.

May 16, 2011 | Registered CommenterStephen Millard

Is there a way to generate the new note with a title with the date automatically input, i.e., Title = "2011.05.25 Daily Journal"?

May 25, 2011 | Unregistered CommenterPaul Masters

Paul. There's another post on how to do just that sort of thing. Check out "Creating a Daily Journal in Evernote"

May 26, 2011 | Unregistered CommenterStephen Millard

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>