Can I interact with Apple Notes app from the command line?

There is an application called Note2txt which will convert your notes from the Notes app to text files. One file for each note. It creates a file for all your notes and writes them into a directory of your choice. It runs pretty quickly taking about 30 seconds for my 700+ Notes.


It appears that Notes are stored in a SQLite DB in the folder:

~/Library/Containers/com.apple.notes/Data/Library/Notes

The sqlite3 command is included with MacOS.

Who knows what format the notes are in -- I doubt it's markdown -- so you'll probably have to convert between this internal format and markdown. Also, there are other files in the directory that SQLite might or might not maintain and any files in the directory may be accessed at any time by the system daemons that sync things with iCloud. Not sure if SQLite supports file locking directly.

EDIT:

You seem to have found nothing in those folders. I am on Catalina, and when I look at NotesV7.storedata I see multiple tables:

ATRANSACTION        ZATTACHMENT         ZNOTEBODY           Z_MODELCACHE      
ATRANSACTIONSTRING  ZFOLDER             ZOFFLINEACTION      Z_PRIMARYKEY

And in ZNOTE I see what look like note titles and other info and ZNOTEBODY has HTML-formatted notes. So that would answer the question: it evidently stores notes internally in HTML format.

EDIT2:

OK, I only see notes in those tables that correspond to On My Mac notes, not iCloud notes.