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