EvContent Handlers

Description

There are three "handlers" here. getTextFromHc - Takes as its parameter some HTML Content (from an Evernote note) and removes everything between markers, returning the remainder as its result. This results in "pretty clean" text, but still leaves a few HTML codes that don't require markers. Its the best I can do for now. getHcInNote - Takes as parameters the name of a notebook and the number of a note item in that notebook, and returns the HTML Content of the note. (You can then feed that HTML Content to the getTextFromHc handler to extract the text.) getTextInNote - Takes as parameters the name of a notebook and the number of a note in that notebook, and returns the text content of that note. It does this simply by calling the two handlers mentioned above. One "problem" with the foregoing is that you need to supply a number for the note you are interested in, and that's not that easy. You might have to write some code to furnish a note title and obtain the note number, or simply get the number of the note that is currently selected. However, I wrote the routines to use a number because that makes it easy to write a "repeat" loop to get the text of all the notes in a notebook. I'll submit a routine to do that later; it will store the notebook name, the note title, and the text content of each note in a "record" and put the records for all notes in a "list".

The Code

-- EvContent Handlers

on getTextFromHc(hc)
-- eliminate stuff between < and > markers
set c to ""
set i to 0
set nText to ""
set numChars to (count characters in hc)
repeat while i < numChars
set i to i + 1
set c to character i of hc
if c = "<" then
repeat until c = ">"
set i to i + 1
set c to character i of hc
end repeat
else
try
set nText to nText & c
end try
end if
end repeat
return nText
end getTextFromHc

on getHcInNote(NbName, numNote)
tell application "Evernote"
activate

set nb to notebook NbName
set theNote to (note numNote) of nb

set ti to title of theNote
set hc to (HTML content of theNote)
end tell
return hc
end getHcInNote

on getTextInNote(NbName, numNote)
set hc to getHcInNote(NbName, numNote)
set txt to getTextFromHc(hc)
return txt
end getTextInNote