I wrote almost this same script before I found yours. One thing lacking in both versions is the retention of the creation and modification dates for each note.
There are methods on the Note object for these dates:
var cdate = note.creationDate
var mdate = note.modificationDate
And what I'd like to do is something like below, to transfer these dates to the exported note files.
var app = Application.currentApplication();
var file = app.openForAccess(Path(filename), { writePermission: true });
app.setEof(file, { to: 0 });
app,setCreateDate(file, { to: note.creationDate});
app,setModifiedDate(file, { to: note.modificationDate});
But I can't find how to (a) format the date objects in this version of Javascript, or (b) find methods to assign the dates to the generated file.
Any ideas, either how to do this, or where to find the right APIs?