Search
« ReaddleDocs Bookmarklet | Main | Mass Tweet Delete »
Sunday
Mar142010

An Improved Template System for Evernote

One of the things that people have frequently asked for in Evernote is for the inclusion of templates.  I wrote a post in November 2009 about how ENSCRIPT could be used to automate the creation of notes in Evernote based on a template.  I've now taken that post which was more a proof of concept and created what I think is an improved system for using templates in Evernote.

This post relates to Windows, but I've now also written an equivalent post about how to do the same thing on an Apple Mac (OS X).
The first thing I looked at was the way the note was formatted.  I noted that ENSCRIPT allows the import of not only TXT files but also ENEX files which is the Evernote Export file type.  This file type will preserve rich formatting (including images) as well as tags (if you tick the box when exporting), so rather than just creating a text file template, exporting a note from Evernote in the ENEX format is significantly better. In fact I don't know why I didn't suggest this in my original post?

The next thing I looked at was improving the flexibility of the batch file.  The original was very much a proof of concept and I was confident that I could make some improvements.  I thought that for a start it would be nice to change the script to something more generic where it could be passed the name of the file to be imported and if necessary the name of the notebook to import the file into.  This really didn't require anything more fancy than a DOS based batch script (as before) and as ever simplicity is good.

One issue I did run into in modifying the script is that according to the ENScript documentation if a notebook is not specified a default notebook will be used.  My assumption was that this would be whichever notebook you specified as the default in Evernote.  However what it actually did was create a notebook called "Import Notes".  Now this was not immediately visible in the notebook list in Evernote on my Windows machine (running Evernote 3.5).  The notes however were visible along with which notebook they were in via the "All Notebooks" view.  Through various tests I actually ended up with several 'Import Notes' notebooks, but closing and re-opening Evernote gave me access to these (local) notebooks and I removed them.  Given that this feature didn't quite work out as I expected I modified the batch script to specify what I want to be the default notebook for imported notes.  So let's take a look at the script I came up with.
@echo off
:CONFIGURE
set ENscriptLocation="C:\Data\Applications\Evernote 3.5\ENScript.exe"
set EvernoteDatabaseLocation="C:\Data\Evernote Data\Databases\evernotedatabase.exb"
set DefaultNotebook="_Inbox"

:START
if x%2==x goto NOTE_ONLY
goto NOTE_AND_NOTEBOOK

:NOTE_ONLY
%ENscriptLocation% importNotes /s %1 /n %DefaultNotebook% /d %EvernoteDatabaseLocation%
goto TIDY_UP

:NOTE_AND_NOTEBOOK
%ENscriptLocation% importNotes /s %1 /n %2 /d %EvernoteDatabaseLocation%
goto TIDY_UP

:TIDY_UP
set ENscriptLocation=
set EvernoteDatabaseLocation=
set DefaultNotebook=
cls
cls
exit
The script is effectively split into five sections.  It could be shortened and made more efficient, but it runs in an instant and this layout makes it easy to walk through how it works.

The first section (labeled :CONFIGURE) specifies some information about how Evernote is installed and about how you want it to work.  It sets up three variables:


  • ENscriptLocation specified the file path to where the ENScript executable is located.  This is distributed as part of Evernote for Windows so you'll probably find it in the folder you installed Evernote to.

  • EvernoteDatabaseLocation is the file path to your Evernote database file.

  • DefaultNotebook is the name of the notebook to put any notes imported by this script into.  I made mine my default notebook (which I named "_Inbox"), but you can specify whichever notebook you like.

The second section of the script (labeled :START) is where the processing begins.  This section simply looks at the parameters being passed to the script to determine what action to take.  The first parameter the script expects is a file path to the note that is to be used as the template, so this would most likely be an ENEX file.  This is a mandatory parameter - you have to have a note to import after all.  The second parameter is optional and specifies which notebook you want the note to be imported into.

The third and fourth sections (:NOTE_ONLY and :NOTE_AND_NOTEBOOK) simply execute ENSCRIPT with the parameters required to import the specified note into the appropriate notebook in your Evernote database.

Finally the last section (:TIDY_UP) just wipes the variables set in the initial configuration and then ensures that the script really does exit at the end (these three lines have been the only way in the past I've ensured that a command window really does close every time).

Whilst running some sample imports I noticed that the notes I was importing to be used as a template were not appearing with the right date and time on them.  Actually they were, but they just weren't what I'd originally expected.  Exporting and importing notes is effectively a backup and restore process.  When the notes are exported they contain information about when they were created.  When they are imported again, that information is retained and so these "new" notes have old dates and times not 'current' ones.  So if like me you find dates and times important we need to tweak the ENEX files used as templates.  The fortunate thing is that this is very straight forward to do.

When you export a file as an ENEX file for use as a template, open it up in your favourite text editor (e.g. Windows notepad).  Search through the file for two sets of tags "<created>" and "<updated>".  In all of my templates this follows just after the "</content>".  I don't use geo-tagging, but it may be that some notes get exported with that so you might want to have a look for that too if you want to keep that data "clean".  Once you have found these tags, delete the tags and any data contained within (e.g. <created>20100310T175541Z</created><updated>20100312T194829Z</updated>).  Once you have done this save and close the file.  You can of course edit the content at this point changing title's, etc., but you can do most of this before you even export.  When you import the file now, Evernote/ENSCRIPT will default the created and updated date and time to the time of import.

So we have a batch script with a bit more flexibility and a template file that we can get much more from than my original text file example.  We can import it at the right time and things seem to be working pretty well.  The only problem is I don't want to be entering commands from the command line.  That's just too onerous.  The final step is finding a better way to get quick and easy access to this system.

Now we could simply create some desktop shortcuts to run the batch script with the appropriate parameters for each note.  My preferred solution however is to use a menu system from the system tray (the area next to the clock on the task bar).  Many portable application launchers exist out there and if you already use one you may like to investigate using that.  I personally use an application called PS Menu which allows me to configure a number of options, is very small and quick and fortunately happens to be perfectly suited to what I want to do.

PS Menu - Evernote Template ConfigurationWith PS Menu running, click on it in the system tray to display the menu and select Options... and then Applications... .  In here you can add folders (I have one for my Evernote templates) and application shortcuts.  Select to add a new application and you'll get a window like the one shown on the right.  Here you can enter a descriptive term for the template, the location of the batch script and the parameters (path to the note template (mandatory) and notebook name to import the note into (optional)).  You can even specify an icon if you have one that's appropriate.  Set the window state to minimized.  Ok everything and your ready to go.

PS Menu for selecting templatePS Menu sits in your system tray and when you click on it it displays the list of applications (or scripts) you have added.  The screenshot on the left shows a sample set-up. When you select the application shortcut for the template you want to import the script will run and moments later it will be in your Evernote notebook.  You may need to switch out and back into a notebook as Evernote doesn't poll for when ENSCRIPT imports something into the currently open notebook, but it should be there.

So here's a summary of the things you'll need for this system:

  1. An Evernote account and Evernote installed on a computer running Microsoft Windows.
  2. ENSCRIPT - which should be included as part of your Windows Evernote installation.
  3. The batch script from above (just copy the content and save it as "en-template.bat" (or something similar)) configured for you installations of the above software.
  4. PS Menu or another system tray menu system that can pass parameters to batch files.
  5. Then it's just a case of  creating the templates in Evernote, exporting them to ENEX files, removing any data you don't want in the templates using a text editor (e.g. removing creation and updated times) and finally adding links to trigger the batch file to import these notes from the menu application.

That's my improved system for Evernote templates.  I hope you find it useful and if you decide to use it, please leave me a comment below.

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (14)

[...] Creating a Daily Journal in Evernote 15/03/2010 Building on yesterday’s post on an improved template system for Evernote I’d like to share with you how I use a variation on this system to create a daily journal [...]

Great post. I need some help with this. Where do you specify the location of the note to import? Believe its in the START section, but where does the path actually go? Can you include placeholders in blue similar to how the CONFIGURE section is formatted?

May 4, 2010 | Unregistered CommenterRandy

Randy.

The batch file is made to receive the note and notebook as a parameter so you don't need to "hard code" it into the file. I'll try and give you an example to try and clarify.

The section of code is saved to a batch file. For the sake of argument let's call it IMPORT.BAT and let's put it in the root of the C drive. We can name it anything we like (with an appropriate extension like .BAT) and put it in any folder we want. But the root of C is a short and simple place for this example.

Let's also have our example template in the root of the C drive and call it EXAMPLE.ENEX. Again it can really be anywhere we like, but we'll give it the ENEX extension for an Evernote exported note. This is a note we exported from Evernote.

From the command prompt (you may also perhaps know it as a DOS prompt), you could type...
C:\IMPORT.BAT "C:\EXAMPLE.ENEX"
... and this would create a new note based on EXAMPLE.ENEX in your default Evernote notebook.

Typing this...
C:\IMPORT.BAT "C:\EXAMPLE.ENEX" "HOLIDAY"
... and this would create a new note based on EXAMPLE.ENEX in your Evernote notebook called HOLIDAY (assuming you have one already made).

Extending this example to add it into PS Menu, you might set up a new application in the launcher as follows...
Name = Create Example in Holiday
Application or Folder = C:\IMPORT.BAT
Parameter = "C:\EXAMPLE.ENEX" "HOLIDAY"

(Click on the first screen shot above to see how the application entry window looks).

If you really really really wanted to, you could "hard code" the template path and notebook into the batch file. %1 would be the path to the note and %2 the notebook.

Just get rid of the START section and choose the NOTE_ONLY or NOTE_AND_NOTEBOOK sectionsas appropriate to which one you want to do.

I hope that all makes sense and sorry for not picking up your comment sooner. This new site doesn't seem to notify me about new comments like Wordpress used to. Maybe I need to find a setting somewhere....

May 8, 2010 | Registered CommenterStephen Millard

What version of Evernote are you using? The Enscript.exe command line options I have seem to be different than what you posted. Actually I can't find the option to import .enex files, only .txt files.

July 1, 2010 | Unregistered CommenterJason

Jason.

I'm using the latest stable release of Evernote on Windows (3.1.5.4.2343 I believe - I'm on my Mac at the moment). However I put together a post last August (2009) that included the ENSCRIPT documentation (ENSCRIPT - Scripting Evernote in Windows). I've checked back and it's included in there so it's been around for at least that long.

For interest it looks as though the first release of ENSCRIPT was in September 2008 with release 3.0.0.842 - according to the Evernote Developer page for ENSCRIPT.

July 1, 2010 | Registered CommenterStephen Millard

Followed the directions on this page and corrupted my Evernote database. Had to re-install the entire database to restore it to functional state. Proceed with caution.

October 2, 2010 | Unregistered CommenterSteve

Steve - I'm really sorry to hear that you experienced such a problem with this process. I've been using this several times a day for months (including some more complex dynamicaly buit templates) and I know many other have too and this is the first I've come across of anyone having issues with it.

The only way I can imagine that a corruption could occur (unless it happens to have been coincidence - Evernote databases have been known to corrupt from time to time on Windows PCs) is if your modified template contains something that means it is no longer compliant with the ENML specifications set out by Evernote - i.e. content was introduced that was interpreted as note structure rather than as content.

Could you provide a copy of your template file?

October 2, 2010 | Registered CommenterStephen Millard

I found this page in the Evernote forums. I use Evernote to make keep notes about calls from customers. I wanted to create a template for a specific customer who calls a lot and gives me the same basic information about a product he needs. I created a template and modified your script but all that happens when I launch it is the command prompt window flashes up for a split-second and then goes away. Nothing else happens.

Here is the modified script I'm using:

@echo off

:CONFIGURE
set ENscriptLocation="C:\Program Files (x86)\Evernote\Evernote3.5\ENScript.exe"
set EvernoteDatabaseLocation="C:\Users\Mike\AppData\Local\Evernote\Evernote\Databases\mnapier.exb"
set DefaultNotebook="Alfa Work Notes"

:START
if x%2==x goto NOTE_ONLY
goto NOTE_AND_NOTEBOOK

:NOTE_ONLY
%ENscriptLocation% importNotes /s %1 /n %DefaultNotebook% /d %EvernoteDatabaseLocation%
goto TIDY_UP

:NOTE_AND_NOTEBOOK
%ENscriptLocation% importNotes /s %1 /n %2 /d %EvernoteDatabaseLocation%
goto TIDY_UP

:TIDY_UP
set ENscriptLocation=
set EvernoteDatabaseLocation=
set DefaultNotebook=
cls
cls
exit

October 7, 2010 | Unregistered CommenterMike

Mike.

It looks like you've just modified the configuration at the top so it shouldn't be too onerous to work out what's going on.

What I'd suggest first of all is double checking the parameter(s) you're passing to the script - definitely the location of your .ENEX template file.

What you could also do is add a PAUSE (just one word on its own line) before the CLS lines. This will then keep the DOS window open (that you've seen flash up) until you press a key to continue after which it should close. This should flag up any error messages that ENSCRIPT puts out.

If you want to test by using the application entry in the Portable Start Menu (rather than from a command prompt), then I'd suggest changing the window state (just below the parameter that's the template file) from "minimized" to "normal" so that the DOS window is more readily visible.

Let me know how you get on and feel free to contact me if you need any help working out where it's failing.

October 7, 2010 | Registered CommenterStephen Millard

Is there a way to make my Windows EverNote Client open up to the screen to edit the newly created note?

April 25, 2011 | Unregistered CommenterRyan

Ryan - I've posted an amended script that should select the new note. You can see it at Evernote note templates - show me the new note.

May 7, 2011 | Registered CommenterStephen Millard

I would like to have a date and time stamp in the body of my note that I create from my template. is there a variable I can put in the template for date and time stamp?

July 14, 2011 | Unregistered Commenterdwilson7

dwilson7 - take a look at my Creating a Daily Journal in Evernote post. I take the DOS "DATE" variable and pull out the year, month and day parts to suit my particular needs of getting the date in yyyy-mm-dd format for the note title.

August 2, 2011 | Registered CommenterStephen Millard

Great stuff!

I used many of the ideas I learned from this post in my variation of template-based note creation in Evernote (see my post on this: http://itamaro.com/2013/09/29/quick-evernote-template-based-note-creation-with-launchy/)

I wanted to integrate this with Launchy, and have some dynamic values applied to the template before importing, so I had to do some extra work, as described in the post I linked above.

September 30, 2013 | Unregistered CommenterItamar O

PostPost a New Comment

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