NotesExporter.workflow
set exportFolder to (choose folder) as string-- Simple text replacingon replaceText(find, replace, subject)set prevTIDs to text item delimiters of AppleScriptset text item delimiters of AppleScript to findset subject to text items of subjectset text item delimiters of AppleScript to replaceset subject to "" & subjectset text item delimiters of AppleScript to prevTIDsreturn subjectend replaceText-- Get an HTML file to save the note in. We have to escape-- the colons or AppleScript gets upset.on noteNameToFilePath(noteName, tag)global exportFolderset strLength to the length of noteNameif strLength > 250 thenset noteName to text 1 thru 250 of noteNameend iftell application "Finder"set convertedFolderPath to exportFolder & tag & ":"if (exists (folder convertedFolderPath)) thenset outputFolder to convertedFolderPathelsemake new folder at exportFolder with properties {name:tag}set outputFolder to the result as stringend ifend tellset fileName to (outputFolder & replaceText(":", "_", noteName) & ".html")return fileNameend noteNameToFilePathtell application "Notes"repeat with theNote in notes of default account--repeat with theNote in notes in folder "New Folder" of default accountset noteLocked to password protected of theNote as booleanset modDate to modification date of theNote as dateset creDate to creation date of theNote as dateset noteID to id of theNote as stringset oldDelimiters to AppleScript's text item delimitersset AppleScript's text item delimiters to "/"set theArray to every text item of noteIDset AppleScript's text item delimiters to oldDelimitersif length of theArray > 4 then-- the last part of the string should contain the ID-- e.g. x-coredata://39376962-AA58-4676-9F0E-6376C665FDB6/ICNote/p599set noteID to item 5 of theArrayelseset noteID to ""end ifif not noteLocked then-- file name composed by id and note title to overcome overwriting filesset fileName to (name of theNote as string) as stringset theContainer to container of theNote-- export the folder containing the notes as tag in bear-- the try catch overcome a 10.15.7 bug with some folderstryif theContainer is not missing value thenset tag to name of theContainerset theText to ("" & theText & "#" & tag & "#") as stringend ifend tryset filepath to noteNameToFilePath(fileName, tag) of meset noteFile to open for access filepath with write permissionset theText to body of theNote as stringwrite theText to noteFile as Unicode textclose access noteFiletell application "Finder"set modification date of file (filepath) to modDateend tellend ifend repeatend tell
解决乱码问题:
find . -name \*.html -type f | \(while read file; doiconv -f UTF-16 -t UTF-8 "$file" > "${file}.bak";mv "${file}.bak" "$file"sed -i "" 's#<h1><br></h1>##g' $filedone);
