It took me some days but I finally finished my Readwise script to split notes up into highlights and keep the metadata. To use this script you have to export all your highlight from Readwise via “Markdown” export and keep all switches off:
I am planning to include some extra features like locations but know it works for me. Every highlight is a standalone markdown file with the title as name plus an incrementing number.
Use it on your own risk and maybe try with test data first:
-- Main: Collect Markdown files and process their content in DEVONthink
tell application id "DNtp"
-- Prompt to select a group
set selectedFolder to display group selector "Select a group in DEVONthink:"
-- Collect Markdown files recursively and process them
my processItems(children of selectedFolder, selectedFolder)
end tell
-- Recursive function to process items
on processItems(selItems, targetFolder)
tell application id "DNtp"
repeat with currentItem in selItems
if type of currentItem is group then
-- Process children of subgroups
my processItems(children of currentItem, currentItem)
else if type of currentItem is markdown then
-- Process the Markdown file content
my processMarkdown(plain text of currentItem, targetFolder)
delete record currentItem -- Optionally delete the original record
end if
end repeat
end tell
end processItems
-- Process Markdown content
on processMarkdown(varText, targetFolder)
-- Initialize variables
set {entryAuthor, entryTitle, entryURL, currentHighlight, metadata} to {"", "", "", "", ""}
set {isHighlight, skipEntry} to {false, false}
set noteHighlights to {}
set counter to 1
-- Extract metadata and highlights
repeat with anEntry in paragraphs of varText
if skipEntry then
set skipEntry to false
-- Skip current entry, go to the next
else if anEntry starts with "- Author:" and not isHighlight then
set entryAuthor to text ((length of "- Author: ") + 1) thru -1 of anEntry
else if anEntry starts with "- Full Title:" and not isHighlight then
set entryTitle to text ((length of "- Full Title: ") + 1) thru -1 of anEntry
else if anEntry starts with "- URL:" and not isHighlight then
set entryURL to text ((length of "- URL: ") + 1) thru -1 of anEntry
else if anEntry starts with "### Highlights" then
set isHighlight to true
set skipEntry to true
else if isHighlight then
-- Handle highlights, including multi-line entries
if anEntry starts with "- " then
if currentHighlight is not "" then set end of noteHighlights to currentHighlight
set currentHighlight to text ((length of "- ") + 1) thru -1 of anEntry
else
set currentHighlight to currentHighlight & linefeed & anEntry
end if
end if
end repeat
-- Add the last highlight (if any)
if currentHighlight is not "" then set end of noteHighlights to currentHighlight
-- Construct metadata
if entryTitle is not "" then set metadata to metadata & "title: " & entryTitle & linefeed
if entryAuthor is not "" then set metadata to metadata & "author: " & entryAuthor & linefeed
if entryURL is not "" then set metadata to metadata & "URL: " & entryURL & linefeed
-- Create and save notes as Markdown files
tell application id "DNtp"
repeat with anEntry in noteHighlights
set varNote to metadata & linefeed & anEntry
set mdFileName to (entryTitle & "_" & counter)
create record with {name:mdFileName, type:markdown, plain text:varNote} in targetFolder
set counter to counter + 1
end repeat
end tell
end processMarkdown