Logging Calendar entries to DayOne

I've been trying to be a little more cognizant of the things going on in my life, and so I've been working on getting to the point where I'm writing up my day and the things that happened. One of the things that I keep forgetting about are the meetings I've taken which are often quite interesting to look back on, so I created some automation to help me out with that.

DayOne is an amazing daily journaling application that I use on my Mac and my phone to keep this information available to me and easy to add. The Mac also has AppleScript which may be the red-headed step-child to some, but is pretty useful for me in pulling data out of the built-in Apple apps.

I wrote the script below to pull entries out of Calendar on a daily basis and add them to DayOne (via their CLI app). It includes the start and end time of the meeting in the note, as well as including the coordinates where you were (this is based on where the machine running the script is - if you have this running from a "central" machine, it may not be as useful to you) at the time of the meeting. The coordinates information requires a secondary package locateme (brew install locateme), which quickly and quietly gives you your GPS coordinates.

Set this job up under cron, and you should be good to go!

set {year:y, month:m, day:d} to current date
set str to (m as string) & " " & (d as string) & " " & (y as string)
set today to date str
set tomorrow to today + 60 * 60 * 24

tell application "Calendar"
	repeat with aCalendar in (get every calendar)
		repeat with anEvent in (get events of aCalendar whose start date is greater than or equal to today ¬
			and start date is less than or equal to tomorrow)

			set noteTitle to (anEvent's summary as string)
			set noteDate to quoted form of (anEvent's start date as string)

			set theStart to do shell script "date -jf '%A, %B %e, %Y at %r' " & (quoted form of (anEvent's start date as string)) & " +'%l:%M'"
			set theEnd to do shell script "date -jf '%A, %B %e, %Y at %r' " & (quoted form of (anEvent's end date as string)) & " +'%l:%M'"

			set fullNote to noteTitle & "
" & (theStart & " - " & theEnd) as string

			set fullNote to quoted form of fullNote

			do shell script "echo " & fullNote & " | /usr/local/bin/dayone2 new --date " & noteDate & " --coordinate $( /usr/local/bin/locateme -f '{LAT} {LON}' ) -t calendar"
		end repeat
	end repeat
end tell