Evernote: Add Text To Beginning of Notes

Description

On the Evernote Forum, I caught sight of this thread, which began:
"When I clip a web page to a new note, I usually want to add a comment at the top of the note. But this seems to be difficult or impossible. Could Evernote insert a blank line at the top of clipped pages so the user could type something there?"
This AppleScript does just that! As written, it adds five line breaks and a horizontal rule line to the beginning of all selected notes... Plenty of space to type some comments! Want to customize it? Just change the HTML code in the "property add_to_top" at the beginning of the script to whatever you require. Hope you enjoy!

WARNING!

There is currently a bug with Evernote's AppleScript implementation that removes any images (and perhaps other resources like audio) from your note when using this script.... Proceed with caution!

The Code

(*
http://veritrope.com
Evernote -- Add Text To Beginning of Notes
Version 1.0
January 10, 2011
Project Status, Latest Updates, and Comments Collected at:
http://veritrope.com/code/evernote-add-text-to-beginning-of-notes
*)


(*
======================================
// CONFIGURATION (USER EDITABLE)
======================================
*)

--CHANGE THIS PROPERTY TO THE HTML CODE YOU'D
--LIKE TO ADD TO THE BEGINNING OF YOUR NOTE.
--(DEFAULT IS 5 LINE BREAKS AND A HORIZONTAL RULE)
property add_to_top : "<br /><br /><br /><br /><br /><hr />"
(*
======================================
// OTHER PROPERTIES (DO NOT CHANGE)
======================================
*)

property noteHTML : ""
(*
======================================
// MAIN PROGRAM
======================================
*)

tell application "Evernote"
    try
        set theNotes to selection
        repeat with theNote in theNotes
            set noteHTML to (HTML content of item 1 of theNote)
            set addString to "<body>" & add_to_top
            set editHTML to my replaceString(noteHTML, "<body>", addString)
            set (HTML content of item 1 of theNote) to editHTML
        end repeat
    end try
end tell

(*
======================================
// HANDLER SUBROUTINES
======================================
*)

--REPLACE SUBROUTINE
on replaceString(theString, theOriginalString, theNewString)
    set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, theOriginalString}
    set theStringParts to text items of theString
    if (count of theStringParts) is greater than 1 then
        set theString to text item 1 of theStringParts as string
        repeat with eachPart in items 2 thru -1 of theStringParts
            set theString to theString & theNewString & eachPart as string
        end repeat
    end if
    set AppleScript's text item delimiters to od
    return theString
end replaceString

5 Responses to “Evernote: Add Text To Beginning of Notes”

  1. Kimberle Crenshaw January 25, 2011 at 9:51 pm #

    Hey Justin,
    I wrote you last fall to thank you for the idea scroll. I mentioned then some work I was doing and asked about some scripts. You kindly replied, but I still didn’t know what I wanted. Now with this new script you’ve just added, I do have an idea. I’d like to put this one together with your idea scroll. You see, I am copying several sentences and passages from my prior articles to put them together into a new text. I’m not always sure where they are going to wind up, but I’d like to simply hightlight them, (I wish I didn’t have to hit “copy” before pasting in evernote but I think there’s nothing to be done about that) and then, prior to the past, fill out a little form like your idea scroll. I’ve edited the idea scroll just a bit to prompt me to say, “What is the Theme” “What Lecture and Section Does it Go In” and “Write more About Where it Fits.” Then, unlike the Idea scroll, whatever I copied would be pasted below.
    I thought I’d see if I could simply add your prior script to this new one, but I can’t even get the new one to work just yet. So, I’m wondering, is this something you can patch together?
    Thanks in advance,
    Kim

  2. Homeway April 10, 2011 at 7:51 am #

    Hi
    I used this script. But there is a bug. When I select a Evernote note with pictures , the pictures will be deleted after running your script.

    • Justin Lancy April 10, 2011 at 2:54 pm #

      I’ve duplicated this error and, to me, it looks like an issue with Evernote’s AppleScript/HTML Parser.

      I’ll reach out to their Mac team and see if we can get a bug report filed for this and, in the meantime, I’ll add a warning on the script’s description!

  3. Matsya August 29, 2011 at 4:16 pm #

    Hi,

    Because the export functions of Evernote suck (ex: tags are lost in a HTML export), I use a TextExpander script in order to put a header in every notes.

    The script works quite well to put all the header’s titles I need, but I have to manually copy/paste the note’s title, the note’s tags, the note’s links, etc.

    I think that there’s a way to do it automatically, but I don’t how. Do you think that is possible? Do you have an idea of how to do it?

    Thanks a lot for your answer!

    -MATSYA-

    P.S: Here is my TextExpander script:

    Title : %fill:title%
    Author : %fill:author%
    Date : %A %e %B %Y, %Hh%M
    ID : id_%Y%m%d%H%M%S
    Tags : %fill:keyw%
    Source :     %fill:src%

    %|