Reproducing an exported Day One markdown journal entry

I suspect some may find this pretty basic stuff. However, what I wanted to do was to reproduce in DT an individual markdown file in the style that matches a Day One journal entry exported in plain text/markdown. In effect, it’s a way of reducing my reliance on Day One for my journal and providing a compatible fall-back solution should I ever wish to stop using Day One.

The result looks like this (minus any journal text detail):

The main problem when tackling this was the fact that the time in the “Date:” section of the header is effectively frozen at the date the markdown file is created (unless you choose to highlight it and update it, of course—which is easy to forget). The solution I arrived at involves this procedure (which is quicker and simpler than it sounds):

  • Create in the relevant folder a new markdown file on which to record your journal entries throughout the day.
  • At the end of the day, after recording the final entry, use the script (details follow) to create the header file and then use a DT smart rule to merge the files, rename the resulting file with the long date of the entry, place the date of the file in a custom metadata field (which allows sorting of journal entries by date) and lock the resulting file.

Confession: in creating this script I relied heavily on some much more sophisticated journal scripts in DT so apologies for plagiarising those.

The other thing to note is that the script really is pretty basic—in the sense that you must enter manually details of the weather and location. I’m not sure it will be useful to anyone so post it here with a certain degree of hesitation (particularly as a complete scripting newbie!).

(* Creates, in the Temp group of the Diaries database,
a new markdown record with the current date and time,
weather and location as the heading. There are prompts
for the current weather and location. The database will
be opened if not already open and the Temp group viewer
window is opened at the end. The idea is then to merge
the day's diary entries from another markdown file 
in the Temp group and then to run the smart rule 
"Complete diary template entry". *)

-- path of the database to open
property pDatabase : "/Users/…"
-- the UUID of group to use
property pGroup : "       "
-- your primary address
property pFirstAddress : "House no. 1, Anystreet, Anytown, Anycountry"
-- your secondary address
property pSecondAddress : "House no. 1, Anystreet, Anyothertown, Anycountry"
-- the next two properties enable any alternative "Other" address to carry over
property pOtherAddress : missing value
property pDefaultOtherLocation : ""
-- set the "Other" location, repeating the value from the previous run
if pOtherAddress is missing value then
	set pOtherAddress to pDefaultOtherLocation
end if

set nextLine to "  " & return

-- Format the time (for UK)
set theDate to current date
if (time of (current date)) > (time to GMT) then
	set theTime to time string of theDate & " BST"
else
	set theTime to timestring of theDate & " GMT"
end if

-- Format the month number (not currently used)
set numMonth to (month of theDate as integer) as string
if the (length of numMonth) < 2 then set numMonth to "0" & numMonth

-- Format the day
set theDay to day of theDate as string

-- Format the year
set theYear to year of theDate as string

-- Format month and weekday names
set theMonth to month of theDate as string
set longWeekday to weekday of theDate as string
-- next line not currently used
set shortWeekday to characters 1 thru 3 of longWeekday

-- Ask for the current weather (pretty basic!)
set nowWeather to display dialog "Enter details of the weather:" with title "Diary entry header: the weather" default answer "°C" with icon note buttons {"Cancel", "Continue"} default button "Continue"
set theWeather to text returned of nowWeather as string

-- Ask for the current location
set myLocationChoices to {"Home1", "Home2", "Other"}
set myLocations to choose from list myLocationChoices with title "Diary entry header: the location" with prompt "Select your current location:" default items {"Home1"}
set myLocation to (myLocations as string)

if myLocation is "Home1" then
	set myLocation to pFirstAddress
else if myLocation is "Home2" then
	set myLocation to pSecondAddress
else if myLocation is "Other" then
	set otherLocation to display dialog "Current location:" default answer pOtherAddress with icon note buttons {"Cancel", "Continue"} default button "Continue"
	set myLocation to text returned of otherLocation as string
	set pOtherAddress to myLocation
end if

-- this handler generates the specified number of tabs
on aTab(num)
	set theTab to ""
	repeat num times
		set theTab to theTab & "    "
	end repeat
	return theTab
end aTab

-- now we've got the basic information get DT to create the relevant record
tell application id "DNtp"
	try
		activate
		-- open the database
		set theDatabase to open database pDatabase
		-- select the group in the database
		set myGroup to get record with uuid pGroup
		-- set the name of the new record
		set recordName to longWeekday & " " & theDay & " " & theMonth & " " & theYear
		-- set the header of the new record
		set theContent to return & my aTab(1) & "Date:" & my aTab(3) & recordName & " " & "at " & theTime & nextLine & my aTab(1) & "The weather: " & my aTab(1) & theWeather & nextLine & my aTab(1) & "Location:" & my aTab(2) & myLocation & nextLine
		-- create the new record
		set myRecord to create record with {name:recordName, content:theContent, type:markdown} in myGroup
		set theContent to plain text of myRecord
		set plain text of myRecord to theContent & return
		-- now ensure we end up in the viewer window of the Temp group
		set root of viewer window 1 to myGroup
	on error errMsg number errNum
		display alert ("An error occurred when adding the document.") & space & errMsg
	end try
end tell

Sorry for the length of this post. I’ve not posted the exact smart rule but can provide details if anyone needs them.

Stephen

1 Like

I had some years of journal in Day One and ended exporting them into PDF and then put the PDF into DT.

Not the best solution but enough for me.

Very nice!
Are you pleased with your results?

Yes, thanks—it provides a perfectly usable fall-back if I ever need, or wish, to stop using Day One. I also learned an awful lot in the process of writing the script—although the outcome is very satisfying!

Stephen

1 Like

Woot!! Glad to hear it.

I’m curious what’s holding you back from switching from Day One.

In terms of exporting existing Day One entries I eventually settled on export as markdown, splitting (because wretched Day One insists on exporting all selected entries in a single, combined file) and importing into Day One. Although I mentioned the process on this forum I have since then posted a rather more refined and updated version on the Hazel forum.

I prefer having each individual entry as an individual markdown file (which enables creation of links between them and tagging individual entries if that’s something you want to do) to having one or two large pdf files. (I should say I have over 18,000 individual journal entries in Day One—now all imported and grouped by year in DT!)

Stephen

Day One, for all its faults, is a dedicated journal app which automatically adds the location, time and weather to each entry (well beyond my limited scripting abilities, as you will have seen!). Further, I synchronise my journal to my iPad so if I’m away without my MacBook Pro I can write on the iPad and know that everything will end up back on the MacBook Pro too. (I suspect DTTG might be mentioned by someone—but I’ve not yet taken that step! :wink:)

The general layout of entries in Day One is quite good (where the timeline shows the first few lines of each entry, the location, etc.). I’m a little anxious about the recent acquisition of Day One by Automattic [sic.] and wonder if one day my grandfathered “Plus” status may disappear. If it does, then so will Day One from my devices—and then I shall use DT.

Anyway, earning Very nice! from you has made my day so let me just bask in a little glory with a nice mug of tea! :grin:

Stephen

:relaxed:
Enjoy the tea!

On a personal note: my favorite tea is hands-down, Lapsang Souchong.
If I had to describe the aroma, it’s like a campfire mixed with beef jerky or an old baseball glove :stuck_out_tongue:

Acquired taste? Yep but so good IMHO.

1 Like

From here, I think two years ago or so, and I think was Christian (DT Developer, not citing him because it is irrelevant hint him), did a full script to add a beautiful Journal entry into DT.

First lines contains all URL and database needed.

Add Journal Entry DT.scpt.zip (18.6 KB)

Ah yes, that was one of the scripts I shamefully plagiarised! However, what I wanted to do was to match the style of the entries already exported from Day One and imported into DT.

Stephen

Do note we integrated that into the Data > New from Template > Productivity templates.

I use DT to store/organize my journal notes and have a fundamental question about “merge the files”
Why the “merge”
My notes remain as individual files, tagged with “!JournalNote” plus any other appropriate tags

I’d guess there are many invidual notes made throughout the day instead of using a single document per day.
Merging into a daily document could definitely make sense to someone inclined to this method of journaling.

I personally use one document per day that I write in as the muse directs me.

I’m sorry I didn’t make this clearer. I have one entry (i.e., effectively, in this case, one markdown file) per day. I would just add to it from time to time during the day.

The difficulty I was trying to overcome, by using the merge route, was explained (probably inadequately) in my rather long initial post:

The main problem when tackling this was the fact that the time in the “Date:” section of the header is effectively frozen at the date the markdown file is created (unless you choose to highlight it and update it, of course—which is easy to forget).

I want the time of the entry to reflect the time of the final contribution of the day to it (OK, OK, it’s sort of OCD!). The only way I could ensure that—other than by trying to remember manually to update the time—was this “merge thing”. I know it sounds a little bizarre: I just couldn’t find another solution to that particular “problem”.

Stephen

You ready for this… ? :slight_smile:

1 Like

Holly Molly!!! Never explored that menu! :man_facepalming: DT, still giving us new joys!!

Which menu? :slight_smile:

The one you mentioned above, sorry, forgot to quote.

This one:

Data > New from Template > Productivity templates.

Ahh, indeed :slight_smile:

Here is a substantially improved version of the script which:

  • does not require merging of records (it adds the header to a record already containing the day’s journal entries—so you have a single record per day which you can update at leisure during the day and then simply use the script to add the header at the end of the day);
  • adds the date to a custom metadata field (called “Diary entry date” with type and format both set to Date);
  • locks the record after adding the header.
(* Amends, in the Temp group of the Diaries database,
a solitary new markdown record (called whatever you wish)
containing the day's diary entries by adding a header with
the current date and time, weather and location. There are
prompts for the current weather and location. The database 
will be opened if not already open. A custom metadata field
("Diary entry date") is set with the date of the entry
(to allow sorting of entries), the record is locked and the
Temp group viewer window is opened at the end. *)

-- set the database you wish to open
property pDatabase : "/Users/…"
-- set the UUID of the group you wish to use
property pGroup : "    "
-- your first preferred location
property pFirstAddress : "House no. 1, Anystreet, Anytown, Anycountry"
-- your second preferred location
property pSecondAddress : "House no. 1, Anystreet, Anyothertown, Anycountry"
-- the next two properties enable any alternative address to carry over
property pOtherAddress : missing value
property pDefaultOtherLocation : ""
-- set the "Other" location, repeating the value from the previous run
if pOtherAddress is missing value then
	set pOtherAddress to pDefaultOtherLocation
end if

set nextLine to "  " & return

-- Format the time (for the UK)
set theDate to current date
if (time of (current date)) > (time to GMT) then
	set theTime to time string of theDate & " BST"
else
	set theTime to timestring of theDate & " GMT"
end if

-- Format the month number (not currently used)
set numMonth to (month of theDate as integer) as string
if the (length of numMonth) < 2 then set numMonth to "0" & numMonth

-- Format the day
set theDay to day of theDate as string

-- Format the year
set theYear to year of theDate as string

-- Format month and weekday names
set theMonth to month of theDate as string
set longWeekday to weekday of theDate as string
-- next line not currently used
set shortWeekday to characters 1 thru 3 of longWeekday

-- Ask for the current weather
set nowWeather to display dialog "Enter details of the weather:" with title "Diary entry header: the weather" default answer "°C" with icon note buttons {"Cancel", "Continue"} default button "Continue"
set theWeather to text returned of nowWeather as string

-- Ask for the current location
set myLocationChoices to {"Home1", "Home2", "Other"}
set myLocations to choose from list myLocationChoices with title "Diary entry header: the location" with prompt "Select your current location:" default items {"Home"}
set myLocation to (myLocations as string)

if myLocation is "Home" then
	set myLocation to pFirstAddress
else if myLocation is "Home2" then
	set myLocation to pSecondAddress
else if myLocation is "Other" then
	set otherLocation to display dialog "Current location:" default answer pOtherAddress with icon note buttons {"Cancel", "Continue"} default button "Continue"
	set myLocation to text returned of otherLocation as string
	set pOtherAddress to myLocation
end if

-- this handler generates the specified number of tabs
on aTab(num)
	set theTab to ""
	repeat num times
		set theTab to theTab & "    "
	end repeat
	return theTab
end aTab

tell application id "DNtp"
	try
		activate
		-- open the database
		set theDatabase to open database pDatabase
		-- select the group in the database
		set myGroup to get record with uuid pGroup
		-- find the existing diary entries for the day (in unique group used for it)
		set myRecords to children of myGroup whose type is markdown
		set recordName to longWeekday & " " & theDay & " " & theMonth & " " & theYear
		-- set the header of the new record
		set theHeader to return & my aTab(1) & "Date:" & my aTab(3) & recordName & " " & "at " & theTime & nextLine & my aTab(1) & "The weather: " & my aTab(1) & theWeather & nextLine & my aTab(1) & "Location:" & my aTab(2) & myLocation & nextLine & nextLine
		-- because there is only one markdown file in the group…
		set myRecord to item 1 of myRecords
		-- change the record name to the day and date
		set the name of myRecord to recordName
		-- add the date to a custom metadata field (to allow sorting of entries)
		add custom meta data theDate for "diaryentrydate" to myRecord
		-- get the content of the day's diary entries
		set theContent to plain text of myRecord
		-- add the header and lock the record
		set plain text of myRecord to theHeader & theContent & return
		set locking of myRecord to true
		-- now ensure we end up in the viewer window of the Temp group
		set root of viewer window 1 to myGroup
	on error errMsg number errNum
		display alert ("An error occurred when adding the document.") & space & errMsg
	end try
end tell

Stephen

2 Likes