Export Script: Title to first line of file

Is there a script available that can export records from a folder and insert the record title in the first line of the file? I want to import a few notes into the Apple Notes application and it only imports the contents of the file. By putting the record title in the first line, I’ll get the notes listed with better headings than the current first line of the record.

Are these plain text files?

No, not so simple. They’re a mix of .txt, .rtf, and .rtfd, with most being .rtf or .rtfd.

I know that complicates it quite a bit.

It should be possible to do this from a script using textutil -cat.

Isn’t that used to combine multiple files? How would that work to get the file name into the file itself?

You would first create a file that just contains the title. For example, something like:

$ echo "Title" > Title.txt
$ textutil -cat rtf Title.txt Body.rtf -output Combined.rtf