Evernote Note Templates - Show me the new note07 May 2011
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 :CONFIGURE call :GET_TIMESTAMP 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" :START if x%2==x goto NOTE_ONLY goto NOTE_AND_NOTEBOOK :NOTE_ONLY set QueryString=notebook:%DefaultNotebook% %QueryString% %ENscriptLocation% importNotes /s %1 /n %DefaultNotebook% /d %EvernoteDatabaseLocation% %ENscriptLocation% showNotes /q "%QueryString%" /d %EvernoteDatabaseLocation% goto :EOF :NOTE_AND_NOTEBOOK set QueryString=notebook:%2 %QueryString% %ENscriptLocation% importNotes /s %1 /n %2 /d %EvernoteDatabaseLocation% %ENscriptLocation% showNotes /q "%QueryString%" /d %EvernoteDatabaseLocation% goto :EOF :GET_TIMESTAMP 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