tell application "Notes"
-- Ensure the "Readwise" folder exists
set folderName to "Readwise"
set theFolder to missing value
repeat with eachFolder in folders
if name of eachFolder is folderName then
set theFolder to eachFolder
end if
end repeat
if theFolder is missing value then
set theFolder to (make new folder with properties {{name:folderName}})
end if
-- Attempt to find the note by title in the "Readwise" folder
set theNote to missing value
repeat with eachNote in (notes of theFolder)
if name of eachNote is "{clean_title}" then
set theNote to eachNote
exit repeat
end if
end repeat
-- If found, append new content, otherwise create the note
if theNote is not missing value then
set the body of theNote to the body of theNote & ¬
"<br>" & "<b>{clean_text}</b>"
else
make new note at theFolder with properties {{name:"{clean_title}", body:"{clean_text}"}}
end if
end tell
The current AppleScript creates duplicate notes.