This script will create a new note is one doesn’t exists and append the note if it already exists.
It works as intended with Notes accounts that are not iCloud. iCloud notes are created the first time correctly, but won’t update thereafter. I know I can make a work around by deleting the note and recreating a new one but I would rather get it working correctly.
To test, change this line to the name of a different account…
set myAccount to first account whose name = "iCloud"
Any ideas?
set newText to "This is my Text"
set AppleScript's text item delimiters to {""}
set htmlText to "<div>" & noteText & "</div>" as text
tell application "Notes"
set myAccount to first account whose name = "iCloud"
tell myAccount
set myFolders to folders whose name = "Notes"
if myFolders ≠{} then
set myFolder to first item of myFolders
else
set myFolder to make new folder with properties {name:"Notes"}
end if
tell myFolder
set myNotes to notes whose name = "Notes Log"
if myNotes ≠{} then
set myNote to first item of myNotes
tell myNote
set its body to (myNote's body) & htmlText as text
end tell
else
set myNote to make new note with properties {name:"Notes Log", body:htmlText}
end if
end tell
end tell
end tell