I worked on a script to import journal entries from a Day One 2 json export. It also does a sort of one-way syncing… if you import the entries, change something in day one, export again, and import again, then it’ll update the record in DT. It sets DT journal entries to locked, so you don’t change it, only ot have it overwritten on the next sync. If you want to modify an entry, you should duplicate it, remove the day one URL (which acts as the link between Day One and DT), and unlock it.
Version 1 strips images from the imported markdown
-- Import Day One journal entries v1
-- Created by Pat Maddox
--
-- This script is provided AS IS!
--
-- Export your Day One journal to JSON, then run this script
--
-- Requires: JSON Helper for AppleScript
-- https://itunes.apple.com/us/app/json-helper-for-applescript/id453114608?mt=12
--
-- Note: this strips any images from the journal entry in DT
--
-- Use at your own risk. I've done my best to create a script that works, but I can't be
-- responsible if it wreaks havoc on your system. Make sure you have good backups!
--
-- Tested on OS X 10.10.5
set theFile to choose file with prompt "Please select your Journal.json file:" of type {"public.json"}
set jsonContents to read theFile as «class utf8»
tell application "JSON Helper"
set json to read JSON from jsonContents
end tell
set entries to entries of json
set defaultTimeZone to do shell script "ls -al /etc/localtime | sed 's/.*zoneinfo\\///'"
repeat with entry in entries
set theUUID to the uuid of entry
set theURL to "dayone2://view?entryId=" & theUUID
set entryText to last item of text of entry
set theName to first paragraph of entryText
set theDateString to creationDate of entry
try
set theTimeZone to timeZone of entry
on error
set theTimeZone to defaultTimeZone
end try
set theCreationDate to timeInZone(theDateString, theTimeZone)
set theText to ""
repeat with theParagraph in paragraphs of entryText
if theParagraph does not contain "
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to find
set subject to text items of subject
set text item delimiters of AppleScript to replace
set subject to subject as text
set text item delimiters of AppleScript to prevTIDs
return subject
end replaceText
on timeInZone(dateString, timeZone)
set theDate to convertDate(dateString)
return TZtoTZ(theDate, "GMT", timeZone)
end timeInZone
on convertDate(textDate)
set textDate to replaceText("T", " ", textDate)
set textDate to replaceText("Z", "", textDate)
set resultDate to the current date
set the year of resultDate to (text 1 thru 4 of textDate)
set the month of resultDate to (text 6 thru 7 of textDate)
set the day of resultDate to (text 9 thru 10 of textDate)
set the time of resultDate to 0
if (length of textDate) > 10 then
set the hours of resultDate to (text 12 thru 13 of textDate)
set the minutes of resultDate to (text 15 thru 16 of textDate)
if (length of textDate) > 16 then
set the seconds of resultDate to (text 18 thru 19 of textDate)
end if
end if
return resultDate
end convertDate
on TZtoTZ(TZ1date, TZ1, TZ2)
return (do shell script ("eraTime=$(TZ=" & TZ1 & " date -jf '%Y-%m-%dT%H:%M:%S' '" & (TZ1date as «class isot» as string) & "' '+%s') ; TZ=" & TZ2 & " date -r \"$eraTime\" '+%Y-%m-%dT%H:%M:%S'") as «class isot») as date
end TZtoTZ
Version 2 imports the photo files
It uses CSS to scale the images to 50% (but doesn’t modify the imported image file in any way). I am holding out hope that DTTG will get x-devonthink-item image linking like desktop has.
-- Import Day One journal entries v2
-- Created by Pat Maddox
--
-- This script is provided AS IS!
--
-- Export your Day One journal to JSON, then run this script
--
-- Requires: JSON Helper for AppleScript
-- https://itunes.apple.com/us/app/json-helper-for-applescript/id453114608?mt=12
--
-- Use at your own risk. I've done my best to create a script that works, but I can't be
-- responsible if it wreaks havoc on your system. Make sure you have good backups!
--
-- Tested on OS X 10.10.5
set theFile to choose file with prompt "Please select your Journal.json file:" of type {"public.json"}
set filePath to POSIX path of theFile
set journalPath to do shell script "dirname '" & filePath & "'"
set jsonContents to read theFile as «class utf8»
tell application "JSON Helper"
set json to read JSON from jsonContents
end tell
set entries to entries of json
set defaultTimeZone to do shell script "ls -al /etc/localtime | sed 's/.*zoneinfo\\///'"
repeat with entry in entries
set theUUID to the uuid of entry
set theURL to "dayone2://view?entryId=" & theUUID
set entryText to last item of text of entry
set theName to first paragraph of entryText
set theDateString to creationDate of entry
try
set theTimeZone to timeZone of entry
on error
set theTimeZone to defaultTimeZone
end try
set theCreationDate to timeInZone(theDateString, theTimeZone)
set theText to ""
try
set thePhotos to photos of entry
repeat with thePhoto in thePhotos
set photoFileName to md5 of thePhoto & "." & type of thePhoto
set photoFullPath to journalPath & "/photos/" & photoFileName
set photoURL to "dayone-image-hack://" & md5 of thePhoto
tell application "DEVONthink Pro"
set thePhotoRecords to lookup records with URL photoURL
if length of thePhotoRecords is equal to 0 then
set thePhotoRecord to import photoFullPath to current group
set URL of thePhotoRecord to photoURL
else if length of thePhotoRecords is equal to 1 then
set thePhotoRecord to item 1 of thePhotoRecords
else
display alert "Error: found multiple photos with URL " & photoURL
error "Found multiple photos with URL " & photoURL
end if
set locking of thePhotoRecord to true
set dayOneURL to ""
set photoRecordURL to "<img src=\"x-devonthink-item://" & uuid of thePhotoRecord & "\" style=\"width: 50%\">"
set entryText to replaceText(dayOneURL, photoRecordURL, entryText) of me
end tell
end repeat
end try
set theText to entryText
tell application "DEVONthink Pro"
set theRecords to lookup records with URL theURL
if length of theRecords is equal to 0 then
set theRecord to create record with {type:markdown, name:theName, plain text:theText, URL:theURL, creation date:theCreationDate} in current group
else if length of theRecords is equal to 1 then
set theRecord to first item of theRecords
if plain text of theRecord is not equal to theText then
set plain text of theRecord to theText
end if
if name of theRecord is not equal to theName then
set name of theRecord to theName
end if
if creation date of theRecord is not equal to theCreationDate then
set creation date of theRecord to theCreationDate
end if
if modification date of theRecord is not equal to theCreationDate then
set modification date of theRecord to theCreationDate
end if
else
display alert "Error: found multiple records with URL " & theURL
error "Found multiple records with URL " & theURL
end if
set locking of theRecord to true
end tell
end repeat
on replaceText(find, replace, subject)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to find
set subject to text items of subject
set text item delimiters of AppleScript to replace
set subject to subject as text
set text item delimiters of AppleScript to prevTIDs
return subject
end replaceText
on timeInZone(dateString, timeZone)
set theDate to convertDate(dateString)
return TZtoTZ(theDate, "GMT", timeZone)
end timeInZone
on convertDate(textDate)
set textDate to replaceText("T", " ", textDate)
set textDate to replaceText("Z", "", textDate)
set resultDate to the current date
set the year of resultDate to (text 1 thru 4 of textDate)
set the month of resultDate to (text 6 thru 7 of textDate)
set the day of resultDate to (text 9 thru 10 of textDate)
set the time of resultDate to 0
if (length of textDate) > 10 then
set the hours of resultDate to (text 12 thru 13 of textDate)
set the minutes of resultDate to (text 15 thru 16 of textDate)
if (length of textDate) > 16 then
set the seconds of resultDate to (text 18 thru 19 of textDate)
end if
end if
return resultDate
end convertDate
on TZtoTZ(TZ1date, TZ1, TZ2)
return (do shell script ("eraTime=$(TZ=" & TZ1 & " date -jf '%Y-%m-%dT%H:%M:%S' '" & (TZ1date as «class isot» as string) & "' '+%s') ; TZ=" & TZ2 & " date -r \"$eraTime\" '+%Y-%m-%dT%H:%M:%S'") as «class isot») as date
end TZtoTZ