Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JMichaelTX/5b65a14929a6cd6add165f8eb3e7daf0 to your computer and use it in GitHub Desktop.
Save JMichaelTX/5b65a14929a6cd6add165f8eb3e7daf0 to your computer and use it in GitHub Desktop.
Evernote Mac AppleScript to Create Summary Note from Extracted Text in Delimiters (EN Mac AS)

Script:

Purpose:

  • Create a new Evernote Note that is a list of all delimited text from all Notes in a specified Notebook

Script Settings Designed to be Changed

-- Change the below properties (in the script) to suit your needs

property nbName : "TestExtractText"
property beginDelim : "***"
property endDelim : "!!!"

Example Note with Delimiters

image

Example of Note Created

Created Note Process

  1. Shows Source Note as a hyperlink back to note
  2. Shows Last Update of Source Note
  3. Excludes empty found items
    • Text between delimiters is either: none, CR, or LF
  4. If no notes are found that have delimiters, then a new Note is NOT created.
    • Instead, a popup dialog is displayed so indicating.

Disclaimer

  • This is a draft script, provided for educational purposes only.
  • It has had only very light testing.
  • I strongly suggest that you create a TEST Notebook to use in testing and further developing this script.
  • Use at your own risk! It works for me, but it DOES create a new Note in your Notebook.

Evernote Discussion

For more info, you may want to visit the Evernote Forum topic concerning this script: Script to Search + Copy

REQUIRED:

  1. Mac OS X Yosemite 10.10.5+
  2. Mac Applications
    • Evernote Mac 6.7+
(*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[EN] Extract Text in Delimiters (AS)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
VER: 1.3 LAST UPDATE: 2016-06-13
PURPOSE:
• Extract text in delimited from all Notes in Specified Notebook
AUTHOR: JMichaelTX
Find any bugs/issues or have suggestions for improvement?
Please post below
CHANGE LOG:
1.3 2016-06-13 BUG FIX: textutil now properly returns plain text
ADDED: Found text that is only CR or LF is now excluded
1.2 2016-06-10 ADDED: Exclude empty found items (nothing between delimiters)
CHANGED: Do NOT produce a Summary Report Note
if no notes are found with delimiters.
1.1 2016-06-08 ADDED to output:
• Source Note Title as hyperlink
• Last Update of Source Note
REQUIRED:
1. Mac OS X Yosemite 10.10.5+
2. Mac Applications
• Evernote Mac 6.7+
REF: The following were used in some way in the writing of this script.
1. Requested by:
Script to Search + Copy
https://discussion.evernote.com/topic/96601-script-to-search-copy/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*)
### SCRIPT SETUP ###
-- Change the below properties to suit your needs
property nbName : "TestExtractText"
property beginDelim : "***"
property endDelim : "!!!"
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set newNoteHTML to "<div id=\"en-note\">" & linefeed & linefeed -- & "<div><br /></div>"
-- Must add "</div>" at END of all text for note --
tell application "Evernote"
set noteList to every note of notebook nbName
set numNotesWithDelim to 0
repeat with oNote in noteList
set noteHTML to HTML content of oNote
set noteText to do shell script "echo " & quoted form of noteHTML & space & "| textutil -format html -convert txt -stdin -stdout"
set AppleScript's text item delimiters to {beginDelim, endDelim}
set parsedList to text items of noteText
--set foundItems to even items of parsedList
set foundItems to {}
repeat with iItem from 2 to (count of parsedList) by 2
##CHG: test for no chars between delimiters ##
set textStr to text of item iItem of parsedList
if (textStr ≠ "") and (textStr ≠ return) and (textStr ≠ linefeed) then
set end of foundItems to item iItem of parsedList
end if
end repeat
if ((count of foundItems) > 0) then ##CHG: Add IF
set numNotesWithDelim to numNotesWithDelim + 1
##CHG: --- CREATE HYPERLINK TO NOTE ---
set noteTitle to title of oNote
set noteLink to note link of oNote
set noteHTMLLink to "<a href=\"" & noteLink & "\">" & noteTitle & "</a>"
set noteUpdated to (modification date of oNote)
set noteUpdated to date string of noteUpdated
set AppleScript's text item delimiters to ("</div>" & linefeed & "<div>")
set textToAddToNote to foundItems as text
log textToAddToNote
##CHG: ADD Note link to output
set newNoteHTML to newNoteHTML & linefeed & ¬
"<div> <br/>" & "Text From: " & noteHTMLLink & " (Updated: " & noteUpdated & ")</div>" & linefeed ¬
& "<div>" & textToAddToNote & "</div>"
end if -- Delimited Text was found
log "end of repeat"
end repeat
##CHG: Make new Note ONLY if Notes with Delimiters were found ##
if (numNotesWithDelim > 0) then
set newNoteHTML to newNoteHTML & linefeed & "</div>"
log newNoteHTML
set titleNote to nbName & ": Weekly Summary " & date string of (current date)
create note with html newNoteHTML ¬
title titleNote ¬
notebook nbName
else
set msgStr to "••• NO Notes were found with the Delimiters •••"
log msgStr
display dialog msgStr with title (name of me)
end if
end tell -- Evernote
@JMichaelTX
Copy link
Author

Update Ver 1.3

CHANGE LOG:

1.3    2016-06-13  BUG FIX:  textutil now properly returns plain text
                   ADDED:    Found text that is only CR or LF is now excluded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment