Monday, February 18, 2013

Notes.app to nvAlt

This morning, I made the decision to dump Notes.app and move to nvAlt for my note-taking needs. I'd been disappointed with the formatting of notes from Notes.app (I prefer basic text with some simple formatting), and I wanted more than a text editor with fifty million text files floating around.
One passion of mine, that I've developed over time, is writing simple automation scripts. In this case, I wanted to copy the wealth of information that I'd built up in notes over time, and move it to nvAlt. I couldn't find a satisfactory script to do that already, so I set about making my own.

Here it is, with some notes:
tell application "Notes"
  repeat with i from 1 to the count of notes
    set noteName to name of note i
    set tempContent to body of note i
    set noteContent to do shell script "echo " & quoted form of tempContent & space & "| textutil  -convert txt  -stdin -stdout"
  
    tell application "nvALT"
      activate
      search noteName
      tell application "System Events"
        keystroke return
        delay 0.1
        set the clipboard to noteContent
        key code 9 using {command down}
        delay 0.1
        keystroke return
      end tell
    end tell
  end repeat
end tell
Fire back and let me know if this is useful to you.