Import to Apple Notes

Thu, Feb 15, 2018

I have been increasing the usage of Apple’s native Notes app in my workflows and wanted to migrate a folder of plaintext files that were originally associated with nvAlt. After an initial test attempt at bulk importing folders of txt files into Notes I encountered two issue:

  1. The file names were lost in Notes
  2. The last date file modified was lost in Notes.

After coming across the two articles listed below and learning some new bash commands, I cobbled together this bash script.

for file in *.txt
    modDate=$(stat -f '%Sm' -t '%Y-%m-%d' "$file")
    header=$(printf '%s\n%s\n%s\n'  "$title" "" "$modDate")
    printf '%s\n%s\n' H 1i "$header" "" . wq | ed -s "$file"

The script uses the ed command to inline add a header to each txt file including the original file name and previous date modified. When imported to Notes the filename will become first line of note and be what is displayed in Notes sidebar.

The majority of the work (and recommendation of using ed command) came from here: Using Mac Terminal to Insert a Line into a Textfile that Contains the Filename - SuperUserStatic

Recommendation for using stat to pull last modified date came from here: Print a file’s last modified date in Bash - Stack Overflow