Scarvy / readwise-to-apple-notes

Export Readwise highlights to Apple Notes.
Apache License 2.0
14 stars 0 forks source link

AppleScript creating duplicate notes #6

Open Scarvy opened 1 week ago

Scarvy commented 1 week ago

The current AppleScript creates duplicate notes.

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