Evernote Daily Journal for Mac OS X02 Jan 2011
Several months back (March 2010 in fact) I posted how to create a daily journal in Evernote on Windows using a bit of script. The script creates a new note in evernote with a dynamically generated title (the current date) and pre-populated with an Evernote tag. Whilst I use this to log everything I do at work, at home I have an Apple Mac that I use most of the time and I hadn’t quite got around to porting the script to OS X … until now.
The original script was a simple DOS batch script but fortunately it was quite simple to port over into AppleScript. On Windows I use a portable application launcher to give quick and simple access to the script, but on my Mac I just call it from my scripts menu on my menu bar (though you could of course save the script as a service in Snow Leopard to assign a shortcut key or use QuickSilver).
The script begins by building the content for the import file. The file
is in the Evernote ENEX format, but it is
fairly simple to read straight from the script below. Should you need to
modify it to include something in the body of the note put the text
between the ‘en-note’ tags. As it stands the tags are actually taken
TAG_DEFINITION constant at the start of the script and the
title is generated by the ReverseDate() function.
With the content built the next step is to write the note content to a
file on the desktop (though you could edit this to be an alternate
location if you prefer). With the file written, Evernote then gets
called to import the file and finally the import file we created is
deleted. The Evernote notebook into which the note is imported is
defined by the
IMPORT_NOTEBOOK constant which again is defined at the
start of the script.
-- Constants set TAG_DEFINITION to "Journal" set IMPORT_NOTEBOOK to "Sand Pit" try -- Build the content of the Evernote file format to write to the import file set theText to "" & return set theText to theText & "" & return set theText to theText & "" & ReverseDate() & "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" & return set theText to theText & "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\"><en-note></en-note>" & TAG_DEFINITION & "" -- Create the import file set theFilePath to (path to desktop as string) & "today journal" & ReverseDate() & ".enex" as string set theFileReference to open for access theFilePath with write permission write theText to theFileReference close access theFileReference -- Import the file into Evernote tell application "Evernote" activate import theFilePath to IMPORT_NOTEBOOK with tags end tell -- Delete the import file tell application "Finder" delete file theFilePath end tell -- Error handling on error errStr number errorNumber display dialog "Unfortunately an error occurred:" & return & "[" & errorNumber & "]" & errStr end try -- Return the current date in format yyyy-mm-dd on ReverseDate() -- Start with the current date set theDate to current date -- Pick out the year set intYear to text -1 thru -4 of ((year of theDate) as text) -- Pick out the month copy theDate to tempDate set the month of tempDate to January set intMonth to text -2 thru -1 of ("0" & 1 + (theDate - tempDate + 1314864) div 2629728) -- Pick out the day set intDay to text -2 thru -1 of ("0" & theDate's day) -- Return the date parts separated by hyphens return (intYear & "-" & intMonth & "-" & intDay) as string end ReverseDate
So that’s it. The principle can of course be expanded to any number of automation scripts you might have logging anything into Evernote, so enjoy.