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 […]

-- 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

There are two “handlers” here - 1 – On QuickSort 2 – On ListSort These are from Beginning AppleScript by Stephen Kochan. The ListSort handler is just a “wrapper” for the QuickSort handler. You call ListSort with a paramater that is a List variable, and ListSort tells QuickSort to sort the List beginning with the […]

-- ListHandlers

on listSort(L)
    return quicksort(L, 1, count L)
end listSort

on quicksort(L, leftIndex, rightIndex)
    if L = {} then return L
   
    set lHold to leftIndex
    set rHold to rightIndex
   
    set |pivot| to item leftIndex of L
   
    repeat while leftIndex < rightIndex
        repeat while item rightIndex of L ≥ |pivot| and leftIndex < rightIndex
            set rightIndex to rightIndex - 1
        end repeat
       
        if leftIndex is not equal to rightIndex then
            set item leftIndex of L to item rightIndex of L
            set leftIndex to leftIndex + 1
        end if
       
        repeat while item leftIndex of L ≤ |pivot| and leftIndex < rightIndex
            set leftIndex to leftIndex + 1
        end repeat
       
        if leftIndex is not equal to rightIndex then
            set item rightIndex of L to item leftIndex of L
            set rightIndex to rightIndex - 1
        end if
    end repeat
   
    set item leftIndex of L to |pivot|
    set oldLeft to leftIndex
    set leftIndex to lHold
    set rightIndex to rHold
   
    if leftIndex < oldLeft then
        quicksort(L, oldLeft + 1, rightIndex)
    end if
   
    return L
end quicksort

This simple handler will return the name of your default Evernote notebook. Useful for avoiding errors caused by sending an empty value for the notebook name via AppleScript.

--DEFAULT NOTEBOOK FINDER
on Default_Notebook()
    tell application "Evernote"
        set EVnotebook to name of (every notebook whose default is true)
    end tell
end Default_Notebook