Search
« Get the path for a file in OS X with an AppleScript | Main | Sample Templates for Evernote »
Saturday
May082010

Evernote Templates on Mac OS X

A little while back I posted about an improved template system for Evernote. This system was based on exporting a note from Evernote, tweaking it in a text editor and then importing it back again whenever you need a new note based on it.  The post was focussed on how to do this in Windows as this is the platform I commonly work with.  I'm now starting to use Mac OS X a bit more and I've extended the system to work on this platform too.


The principles are essentially the same on OS X as they are on Windows.  The first step is to create a note in Evernote that will be the template you want to use.  Once you are happy with your template, you will want to export the note.  To do this examine the File menu in Evernote and chose Export... .  You can then save the note to a location of your choice.  Please note that you want to export in Evernote's XML file format (ENEX format) and if you want your tags to remain intact (and I almost always do), ensure that the Include tags for each note tick box is ticked.  Evernote XML note files are of course the same across platforms so if you have any templates already on Windows or have some to download, then you can of course just copy them straight to your Mac (or use a file synchronisation and storage system like Dropbox to keep them in line).


Now we have our template exported we could just import it from here, but it's worth tweaking the XML file a little bit so that we can do things like get the dates to more accurately match when we create the new note based on the template and not the date on which the template was exported.  To do this you'll need to use a text editor such as the standard TextEdit app.

Once the note file is open in your text editor search through the file for two sets of XML tags (key words between angular brackets - not the same as Evernote tags) "<created>" and "<updated>" (this should be found just after the text "</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 the "<created>" and "<updated>" XML tags, delete them and any data contained within (e.g. <created>20100310T175541Z</created><updated>20100312T194829Z</updated>).  Once you have removed these XML data items, save and close the file.  You can of course edit the content at this point changing title's, etc., but you can do most(/all?) of this before you even export.  Importing the file now will default the created and updated date and time to the time of import.


So our template is now ready to import.  On Windows this was done by using a batch script with a few parameters and a third party free application launcher that sits in the system tray.  On the Mac we are going to do things in a similar way, but as you might expect there are some differences.


On Windows I resorted to using the command line tool for Evernote known as ENSCRIPT.  The integration on the Mac for Evernote is through AppleScript and so we need a little bit of AppleScript to help us with the import.  I always describe myself as a "lazy programmer".  I don't want to create extra work for myself so I always look to write code that I can use elsewhere and not have to change to do it.  So my Windows batch file that calls ENSCRIPT uses parameters.  I was going to reproduce this in AppleScript but it really wasn't worth it as the script is so simple and the easy way to run it is intrinsically linked to the script file.  So fire up your AppleScript editor and put the following few lines of code into it - we'll need to amend it though.


tell application "Evernote"
	activate
	import "/Users/stephen/Documents/Evernote Templates/My First Template.enex" to "My Notebook" with tags
end tell

As you might guess the third line is the one we need to modify.  The text in double quotes immediately after the word import is the location of the template file we want to import. In this example the template file I'm importing is called 'My First Template.enex' and is located in a folder I created called 'Evernote Templates' within my 'Documents' folder.  Simply amend this to the location of the template file you exported earlier.


The next part of the line says 'to "My Notebook"'.  This can be considered optional.  If you want the new note to be imported into a specific notebook, change "My Notebook" to the name of your notebook.  If you don't specify it, it will just be imported into whatever your default Evernote notebook is.


The final part of the line specifies that you want to include the tags from your template note when you import it.  Again, you will usually want to do this.


Save the script to your scripts folder with a meaningful name.  I've created a sub-folder in my scripts folder just for Evernote, so in my case I saved the script to "/Users/stephen/Library/Scripts/Evernote".  This script now appears in my scripts menu in my menu bar (in a sub-menu folder called Evernote).


Now if you're familiar with AppleScript'ing, you might know that there are also scripting folders for applications.  In my case I have "/Users/stephen/Library/Scripts/Applications/Evernote"  Putting the script file in here may seem like a better option than creating your own folder for Evernote scripts.  Well this is a 'horses for courses' choice. Personally I like to create a new note from a template in Evernote irrespective of what application I'm running at the time.  If I put the script in the Evernote specific folder then I'll only see it when I'm already in Evernote.  Putting it in a folder that's available all the time means I could be browsing the web, think to myself that I need to log a new idea into a new note based on a template and I can just have the script automatically activate Evernote and generate my new note.


Hopefully that's fairly painless and now Evernote Mac users can also benefit from the efficiency improvements the template system can bring.

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (6)

I found that with the templates you created (thank you very much, btw) I also had to remove the export-date attribute on the en-export tag, otherwise it used that date as the creation date. So went from:

<en-export export-date="20100505T212338Z" application="Evernote" version="Evernote Mac 1.8.2 (81703)">

to

<en-export application="Evernote" version="Evernote Mac 1.8.2 (81703)">

June 7, 2010 | Unregistered Commenterdosboy

I was wondering if I could create a note from a template using AppleScript to define the title using a prompt. For example, one notebook I use contains the name, employer, and job description of people I meet at conferences, plus an image of their business card. I want the script to prompt me for the name of the person to add, then to create a note with the name as the title.

I've used "create note from file" to create a note from the XML file. I've deleted the <title> tags in that file. Here's my script:

set dialogResult to display dialog "Enter a name." buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel" default answer "Name"
set noteTitle to text returned of dialogResult
tell application "Evernote"
activate
create note title noteTitle from file "/Users/X/Documents/IP Template.enex" notebook "Conferences"
end tell

This creates a note from the template titled "Untitled Note". Do you have any idea how to fix this?

August 4, 2010 | Unregistered CommenterMaarten

Maarten.

I didn't have much success with create note the from file option with the things I've been wanting to do, but I had a good success rate with the import option.

I don't think the create note from file syntax supports using the title. I have a post elsewhere on how I create a daily journal note in Evernote dynamically on my Windows install which dynamically generates the date in the title. The principle is to write the ENEX import file with the title included and then import. I haven't gotten around to adapting it for the Mac yet (but I'll try to soon), but the principle can be applied to your need. Take a look at the code below and it should help.

tell application "Finder"
-- Get user input for title
set strTitle to text returned of (display dialog "Enter a title:" default answer "")

-- Create template file
set strPath to "/Users/admin/Documents/Scripts Lab/temp.enex" as string
set fhTemplate to open for access strPath with write permission
write "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" to fhTemplate
write "<!DOCTYPE en-export SYSTEM \"http://xml.evernote.com/pub/evernote-export.dtd\">" to fhTemplate
write "<en-export application=\"Evernote\" version=\"Evernote Mac 1.8.1 (79826)\">" to fhTemplate
write "<note><title>" & strTitle & "</title><content><![CDATA[<?xml version=\"1.0\" encoding=\"UTF-8\"?>" to fhTemplate
write "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">" to fhTemplate
write "<en-note style=\"word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; \">Some note content</en-note>]]></content><tag>Test</tag><note-attributes></note-attributes></note>" to fhTemplate
write "</en-export>" to fhTemplate
close access fhTemplate

-- Import template file into Evernote
tell application "Evernote"
activate
import strPath to "Sand Pit" with tags
end tell

-- Delete the template file
do shell script "rm \"/Users/admin/Documents/Scripts Lab/temp.enex\""
end tell

This includes a tag and some content (it was a quick proof of concept), but the title is purely generated by the user input. I haven't put any error handling or the like but hopefully you can see what I mean.

August 5, 2010 | Registered CommenterStephen Millard

I don't understand what the deal is with exporting these notes... why not just create a local notebook in evernote called "Templates" and just create your template notes directly in evernote. Then you can just duplicate the note when you want to use it, edit it with the new info and drag it into what ever other notebook you want, leaving the original in the "Templates" notebook. I just don't get all the jumping through hoops. I have been using my own temples with a "Templates" notebook for nearly a year now, so I have no clue why everyone is trying so hard to make a simple act so complicated.

September 3, 2010 | Unregistered CommenterJonathan

I can only speak for myself on this, but when you want to duplicate a note I think currently you have to do it with several steps (I wish there was a duplicate note option on the desktop client context menus). You find the template note, copy the content, create a new note, paste the content into it. Then repeat for the title. Then list the tags and type them into the new note (I don't recall being able to multi-copy and paste in any of the desktop clients) but there are views that let you list them or pop the notes open side by side. Then set the notebook for the new note and then you can amend it for the content you want to add to it. This for me could be quite a few steps that I see being as simple as a couple of mouse clicks or even a hot key combo with the automation option I've suggested.

You could also manually export and import the note each time but again that's a bit of a pain and then you have to go back and remove it and if your keeping the templates in Evernote and update it you have to remember to duplicate it out to disk. With the manual export/import, you also get some of the data you might not want (such as creation date) creeping back in which you then need to amend.

The option of doing it the way I've described in the post has three benefits for me.
1) It makes it quick and easy to access. One list of templates and when I select the template - bang, it creates the new note in the right place with the right meta data.
2) It ensures that I get exactly the information I want, where I want it, with no meta-data remnants that I don't want creeping in and any that I do want to retain are.
3) It also allow me to script things into the note such as the date into the title, snapshots of key parts of system logs into the content, or even to be able to pull off daily cartoons from different web sites and pop them into a single note at the click of a button.

At the end of the day I'm just really lazy and I don't like being repetitive. The developer part of my brain just keeps telling me that if I do the same thing several times to achieve the same outcome I can probably automate it in some way and save myself a bit of time.

September 3, 2010 | Registered CommenterStephen Millard

I'm writing these scripts again on a clean install of Mavericks. Works perfectly. I just wanted to add that you can create an Automator application with the action of Utilities > Run Applescript and paste the tailored code into the (* Your script goes here *) section. Name the application something unique and call it instantly with Spotlight.

If anyone has a method to make the new note appear in its own window in the foreground on a mac please let me know.

September 1, 2014 | Unregistered Commenterviiiupndhead

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>