Notes script to access notes in specific folder

applescriptautomationnotes.app

I have tested this Notes export script (https://github.com/alexwlchan/notes-export/blob/master/notes-export.scpt). It seems to work, but the issue is that I want to specify a specific Notes folder to export, rather than every single one.

The issue is the main loop clause:

repeat with theNote in notes

"notes" is a Notes field that is a collection of all notes. However, I only want notes in a specific Notes directory. I have no problem specifying the Notes folder by name and having the script confirm that the folder actually exists. Unfortunately, I don't see this documented anywhere.

How do I, in AppleScript, get the list of notes in a specific Note folder? I also need to get the notes's path, since in some cases the Notes directories I am exporting in turn have sub-directories.

Best Answer

Try:

tell application "Notes"
    set myFolder to first folder whose name = "FolderA"
    set myNotes to notes of myFolder
    repeat with theNote in myNotes
        -- insert your code here
    end repeat
end tell