An Improved Template System for Evernote14 Mar 2010
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 specifies 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.
With 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 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:
- An Evernote account and Evernote installed on a computer running Microsoft Windows.
- ENSCRIPT - which should be included as part of your Windows Evernote installation.
- 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.
- PS Menu or another system tray menu system that can pass parameters to batch files.
- 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.