Apple Notes–Get the Name of All Notes not in "Recently Deleted"?

The following successfully retrieves the name of all Apple Notes that are not in the Recently Deleted folder, but execution runs for almost 60 seconds for a relatively low number of notes (265).

set noteSubset to {}
tell application "Notes"
	set theFolder to folder "Recently Deleted"
	set allNotes to notes
	repeat with aNote in allNotes
		if container of aNote is not theFolder then
			set end of noteSubset to name of aNote
		end if
	end repeat
end tell

Does anyone know a method that can be used to generate this list more quickly?

Jim, your script took 2 minutes 40 seconds to run the Notes on my Mac. The code below took just 14.25 seconds. It iterates through the item numbers of a list, rather than the objects in a list. It also gets only the desired notes, rather than getting all notes and discarding the unwanted ones. Hope that helps.

Stan C.

set noteSubset to {}
tell application "Notes"
	set myFolders to folders whose name is not "Recently Deleted"
	repeat with i from 1 to (count myFolders)
		set noteSubset to noteSubset & notes of item i of myFolders
	end repeat
end tell
return noteSubset
1 Like

Actually, I just realized there’s an even faster method. Less than a quarter second on my Mac. Fast enough? :wink:

Stan C.

tell application "Notes"
	tell (folders whose name is not "Recently Deleted")
		set folderNotes to notes of it
	end tell
	set noteSubset to {}
	repeat with i from 1 to (count folderNotes)
		set noteSubset to noteSubset & item i of folderNotes
	end repeat
end tell
return noteSubset
1 Like

Stan, thank you very much for weighing in and sharing your script!

I see that your script returns the subset of note objects, but I’m trying to get a list of the note names (aka note titles).

This is very fast, but returns the names for every note, including the ones in the the Recently Deleted folder.

tell application "Notes"
	get the name of every note
end tell

I tried modifying your script as follows, but for some reason that I don’t understand, this returns an error.

tell application "Notes"
	tell (folders whose name is not "Recently Deleted")
		set folderNotes to notes of it
	end tell
	
	set nameSubset to {}
	repeat with i from 1 to (count folderNotes)
		set nameSubset to nameSubset & name of (item i of folderNotes)
	end repeat
end tell

Interestingly, this script works, but again it’s very slow, albeit about twice as fast as my original script.

tell application "Notes"
	tell (folders whose name is not "Recently Deleted")
		set folderNotes to notes of it
	end tell
	
	set noteSubset to {}
	repeat with i from 1 to (count folderNotes)
		set noteSubset to noteSubset & (item i of folderNotes)
	end repeat
	
	set nameSubset to {}
	repeat with i from 1 to (count noteSubset)
		set nameSubset to nameSubset & name of (item i of noteSubset)
	end repeat
	
end tell
return nameSubset

Is there something else I’ve missed?