4

I like how my notes in the Notes App gets synced via iCloud. I spend most of my time in the terminal during the day, so it's convenient for me to keep notes in a text file. At the moment I simply copy-paste my note to the Notes App, so I can review them in bed on my phone.

Can I skip manual copy-paste and somehow directly push my text file from the command line?

  • Hey Adam! I thought of editing notes database and found this related question. Seems very tricky to me. Also, would you be able to use AppleScript? apple.stackexchange.com/questions/295569/… – ankii Jul 20 at 23:56
  • @ankiiiiiii thanks I think I can try the AppleScript route. Thanks for the link! – Adam Lee Jul 21 at 0:04
  • 1
    make new note at folder "Notes" with properties {name:"this is a test", body:BODYTEXT} expects the BODYTEXT to be in HTML format, otherwise line breaks get lost. So you need a way to pre-process your text notes. – nohillside Jul 21 at 9:03
1

The following might do or at least get you started:

#!/usr/bin/osascript

on run argv
    set unixPath to item 1 of argv
    do shell script "sed 's/$/<br>/' '" & unixPath & "' > /tmp/tmp"
    set bodytext to read POSIX file "/tmp/tmp"
    do shell script "rm -f /tmp/tmp"

    tell application "Notes"
        tell account "iCloud"
            make new note at folder "Notes" with properties {name:unixPath, body:bodytext}
        end tell
    end tell
end run

Save in a convenient place, make it executable and pass the name of the file to be converted into a note as the first parameter.

PS: I didn't do a lot of testing on this, so handle with care. It has no error handling at all, so running it without an argument, or with the name of an non existing file will fail in interesting ways. Also, the HTML "conversion" is rather rudimentary, any leading spaces or tabs at the beginning of a line will be lost for instance. If a full HTML conversion is needed it might be easier to do this within a shell script first and only use Applescript for the note creation at the end.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .