Find me on...
LinkedInPersonal TwitterPersonal Google+SAP TwitterROC Google+QuoraXingKloutSAP Community Network

Search

« AUA Telecoms Conference 2011 - Day 1 | Main | Looking back on blogging 2010 »
Sunday
Jan022011

Evernote Daily Journal for Mac OS X

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 form the 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() & "" & return
	set theText to theText & "]]>" & 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.

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (3)

Hi

Wow, templates for Evernote. Am I ever jazzed! I tried to email you directly but the security code on your email kept claiming that I didn't have it right (after several tries, and refresh of the screen for a new code, etc.).

I'm very interested in generating a few of my own templates and wanted to understand what you are doing here. With the AppleScript. I tried your script and all I got in Evernote was an empty note. What am I missing in the set up? Am I suppose to change the path to desktop as string, or one of the constants?

Cheers,

andrea

January 11, 2011 | Unregistered CommenterAndrea MacDonald

Andrea. This particular script does create an "empty" note by design as I just enter into it the stuff I do each day. The dynamic building bit that the script does was really around the fact that I wanted to create the note each day with a title based on the date of the day. So that's the real dynamic content and why the script is building the note piece by piece. I also pulled out the inclusion of the "Journal" tag by putting it in a constant just so people could see the basic structure of the note file itself.

If you want to build some dynamic content into the body of the note you would add your content between <en-note> and </en-note> (line 10 of the script).

If you don't want to build any content dynamically but rather have it all as static content that you modify manually once it has been created, then you should be able to just get away with reading through my Evernote Templates on Mac OS X post. The AppleScript for that is just four lines. You might also be interested in looking through the sample Evernote templates page?

January 12, 2011 | Registered CommenterStephen Millard

Made a couple improvements and fixes - note, I'm running 10.6

1. It didn't like the space in "today journal" and so would error out when doing the delete file theFilePath. Once I removed the space. voila!

2. doing just delete file dumps it into trash, meaning that clogs up. I changed that line to
do shell script "rm -r " & theFilePath
Permanently deletes the file

January 20, 2011 | Unregistered CommenterEd Roden

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>