Jump to content

Script to Search + Copy


Recommended Posts

I want to automatically extract any text between two specific subheaders (say ***** and !!!!!) from all notes in a notebook into a single note every week. Has anyone ever written a script to search for and copy/export parts of notes? Any thoughts on how it could be done?

 

Thanks!

Link to comment
  • Level 5*
On June 2, 2016 at 2:11 PM, dannyp said:

I want to automatically extract any text between two specific subheaders (say ***** and !!!!!) from all notes in a notebook into a single note every week. Has anyone ever written a script to search for and copy/export parts of notes? Any thoughts on how it could be done?

I think you'll have to take this outside of Evernote if you need the search.
Inside Evernote, special characters like * and ! are removed for search indexing.

Maybe you can use a tag to identify the notes to process.

In my backups, I maintain a copy of my notes in HTML format.  
I could search that backup.

My solution is write a script (Mac Applescript) and generate 1 or more notes

Use Cases

  1. Generate task notes from meeting minutes
  2. Extract tag info from my exported HTML notes
    Thanks to @JMIchaelTX, I learned the tag info is stored as 
    <meta name="keywords" content="!Journal"/>

Script Details: <to follow>

Link to comment
  • Level 5*
On 6/2/2016 at 4:11 PM, dannyp said:

I want to automatically extract any text between two specific subheaders (say ***** and !!!!!) from all notes in a notebook into a single note every week. Has anyone ever written a script to search for and copy/export parts of notes? Any thoughts on how it could be done?

Sounds like a good idea.  I did not have such a script, but it caught my interest.  So here is a DRAFT script, lightly tested, that you can use to get started.  I can immediately think of lots of improvements I would want, but I'll leave that up to you.  If you do make any improvements, please post your script back here so others can benefit as well.

If you find any bugs or issues, please post back here.

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.

EDIT:  2016-06-08 20:15 CT  -- See Revised Script Below.

EDIT:  2016-06-10 21:03 CT (Fri)

Going forward, this script will be maintained in the Github Gist:
EN Mac Create Note from Text in Delimiters.applescript 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DRAFT Script (lightly tested, use at your own risk)


### SCRIPT SETUP ###
-- Change the below properties to suit your needs

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

--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

set newNoteHTML to "<div id=\"en-note\"><div><br /></div>" & linefeed
-- Must add "</div>" at END of all text for note --

tell application "Evernote"
	
	set noteList to every note of notebook nbName
	
	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  -convert txt  -stdin -stdout"
		
		set AppleScript's text item delimiters to {beginDelim, endDelim}
		
		set parsedList to text items of noteText
		
		--set foundItems to even item of parsedList
		set foundItems to {}
		repeat with iItem from 2 to (count of parsedList) by 2
			set end of foundItems to item iItem of parsedList
		end repeat
		
		set AppleScript's text item delimiters to ("</div>" & linefeed & "<div>")
		set textToAddToNote to foundItems as text
		log textToAddToNote
		
		set newNoteHTML to newNoteHTML & linefeed & ¬
			"<div>" & textToAddToNote & "</div>"
		
		log "end of repeat"
	end repeat
	
	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
	
	
end tell -- Evernote

 

Here is the Note HTML that it generates:

<div id="en-note"><div><br /></div>

<div>Text in Middle of line</div>
<div>First Line here</div>
<div>Second Line here</div>
</div>

Example Note Used for INPUT:

EN-Mac-6.6-Example-Note-Extract-Text.png

Example Note Created Using Extracted Text

EN-Mac-6.6-Example-Note-Created.png

Link to comment
  • Level 5*

>>So here is a DRAFT script, lightly tested, that you can use to get started.

Nice job of coding to parse the text

My initial thought was to use the first delimiter, but then walk through the parsed text to find the terminating delimiter; text 1 thru (offset of "!!!" in parcedText)

This is an alternative to your approach of using every second parsedList item.  A missing endDelim is going to ruin your day

 

 

Link to comment

@JMichaelTXAwesome, thank you so much! This is tremendously helpful!

 

I am doing the following to get the title of the origin note, so that I know where the copied text is coming from:

set originTitle to title of oNote

set foundItems to {}

if (count of parsedList) > 1 then set end of foundItems to originTitle

 

Question: How do I get the link of the current oNote so that the title is a link to the note the summary came from? I can't find it anywhere in the documentation.

 

The only other change that I will make is to have separate scripts to create notes in different notebooks depending on which subheader I write under. For example, I will have a Key Learnings notebook and a To-do list notebook that all come from a Meetings notebook that I already have. That was as simple as creating a targetNb property and changing the beginDelim and endDelim.

Link to comment
  • Level 5*
10 hours ago, dannyp said:

Question: How do I get the link of the current oNote so that the title is a link to the note the summary came from? I can't find it anywhere in the documentation.

 

In the script editor app, you can open the dictionary for Evernote and find all the attributes for the Note element

You're already using title of oNote
You can also use note link

nNoten : A note.

elements

contains attachments; contained by collection windowsnote windowsnotebooks.

properties

title (text) : The note's title.

creation date (date) : The note's creation date.

modification date (date) : The note's last modification date.

subject date (date or missing value) : The date associated with the note's content.

source URL (text or missing value) : The note's source URL.

latitude (real or missing value)

longitude (real or missing value)

altitude (real or missing value)

ENML content (text, r/o) : The note's content in ENML representation.

HTML content (text) : The note's content in HTML representation.

tags (list of tag) : The tags assigned to this note.

notebook (notebook, r/o) : The notebook containing this note.

note link (text, r/o) : A URL specifying this note. NOTE: if this note is in a synchronized notebook but has not yet been synchronized itself, the result will be nil.

reminder time (date or missing value) : The reminder time for the note.

reminder done time (date or missing value) : The time the reminder for the note was marked completed.

reminder order (date or missing value) : The reminder order time for the note. When not empty, this is what indicates the note has a reminder. To add a reminder to a note, typically set its reminder order to the current date.

responds to

append.

Link to comment
  • Level 5*
On 6/8/2016 at 9:56 AM, dannyp said:

@JMichaelTXAwesome, thank you so much! This is tremendously helpful!

You're quite welcome.  I'm glad you found it useful.

On 6/8/2016 at 9:56 AM, dannyp said:

I am doing the following to get the title of the origin note, so that I know where the copied text is coming from:

set originTitle to title of oNote

set foundItems to {}

if (count of parsedList) > 1 then set end of foundItems to originTitle

It looks like you are reusing the original variable names for a different purpose.  That is a bad practice.  Better to create new variable names for different data.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

EDIT:  2016-06-10 20:45 CT (Fri)

  • Revised Script (Ver 1.2)
  • ADDED:  Exclude empty found items (nothing between delimiters)
  • CHANGED:  Do NOT produce a Summary Report Note  if no notes are found with delimiters.
    • If no notes are found, a popup dialog is displayed, so stating.

Going forward, this script will be maintained in the Github Gist:
EN Mac Create Note from Text in Delimiters.applescript 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here is revised script that ADDS to the new Summary Note:

  1. Source Note Title as hyperlink
  2. Last Update of Source Note

Example of Revised Summary Note

EN-Mac-6.6-Example-Note-Created-V1.1.png

Script Ver 1.2 (Revised 2016-06-10 20:45 CT)

(*
===============================================================================
  [EN] Extract Text in Delimiters (AS)
===============================================================================

VER:   1.2    LAST UPDATE:   2016-06-10

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

Please let me know if you find any bugs or issues.

 

Link to comment

Awesome, thanks! Good call-out on style. And the date updated is a good idea.

1) Is there a way for me to get the author's name too? I was thinking that I could get the author's name from the "Created by" field, which would be ideal. An alternative might be to get the author's initials from a tag that authors would use. I don't think I should use the "Author" field because if you duplicate and modify a note, the original author remains. I saw that @DTLow mentioned that tag info is stored as 
<meta name="keywords" content="!Journal"/> but wasn't sure how to use that info.

 

2) @DTLow You wrote, "My initial thought was to use the first delimiter, but then walk through the parsed text to find the terminating delimiter; text 1 thru (offset of "!!!" in parcedText)"

How would walking through the text eliminate the devastation of a missing terminating delimiter? Wouldn't it end up including everything in the rest of the note regardless of approach taken.

Link to comment
  • Level 5*
20 hours ago, dannyp said:

2) @DTLow You wrote, "My initial thought was to use the first delimiter, but then walk through the parsed text to find the terminating delimiter; text 1 thru (offset of "!!!" in parcedText)"

How would walking through the text eliminate the devastation of a missing terminating delimiter? Wouldn't it end up including everything in the rest of the note regardless of approach taken.

Lets say you have an example of a note that contains 50 sections of text to extract, in the form of        extra typing ****aaaaa!!!!!  extra typing *****bbbbb!!!!! extra typing ....
You only want the aaaaaa and bbbbbb and not the extra typing

If you parse with the only first delimiter, you will get 51 extracts in the form of
     extra typing
     aaaaaaaaaaaa !!!!! extra typing
     bbbbbbbbbbb !!!!! extra typing
A second pass is required to remove the the extra typing and can be done using the offset command.  
No big deal if the delimiter is missing or mistyped

If you parse with the two delimeters, you will get 101 extracts in the form of
      extra typing      
      aaaaaaaaaaaa
      extra typing
     bbbbbbbbbbb
     extra typing

A second pass is required to remove the extra typing. An assumption was made that this would be done by only using every second line.

 

Link to comment
  • Level 5*
1 hour ago, dannyp said:

1) Is there a way for me to get the author's name too? I was thinking that I could get the author's name from the "Created by" field, which would be ideal. An alternative might be to get the author's initials from a tag that authors would use. I don't think I should use the "Author" field because if you duplicate and modify a note, the original author remains. I saw that @DTLow mentioned that tag info is stored as 
<meta name="keywords" content="!Journal"/> but wasn't sure how to use that info.

I was talking about my exported html notes, which is another discussion
and Author doesn't get included in the export

You can retrieve the "Author" field. Its not listed in the Applescript dictionary, but I used
             set theAuthor to author of oNote
There is no "Created by" field.
You can retrieve tags from the original note.

Also with our new skills (thanks JM), we can extract any part from the text of the original note if there is a consistent delimiter, like your "Created by" example

 

Link to comment

I don't want to use author because if I duplicate a note template, my note retains the note template's author. In other words, the author isn't always accurate.

There's a "Created by [name] and shared with [#] people" at the top of every note. Is there no way to access that name?

How can I retrieve tags from a note that contain "@" as in "@DP"?

Thanks!

Link to comment
  • Level 5*
5 minutes ago, dannyp said:

I don't want to use author because if I duplicate a note template, my note retains the note template's author. In other words, the author isn't always accurate.

There's a "Created by [name] and shared with [#] people" at the top of every note. Is there no way to access that name?

Its accurate for my notes.  Of course unless we're talking about a shared notebook, all the notes will have you as the author.

My understanding is the note has a single field called Author.

Link to comment
  • Level 5*
5 hours ago, dannyp said:

How can I retrieve tags from a note that contain "@" as in "@DP"?

set theTagList to tags of oNote                  
repeat with theTag from theTagList  
   If (characters 1 thru 1 of  theTag) is "@" then

Correction: use       name of theTag

Link to comment

Hmm I'm getting an error:

error "Evernote got an error: Can’t get characters 1 thru 1 of tag \"$ClassNotes\"." number -1728 from characters 1 thru 1of tag "$ClassNotes"

Link to comment

@JMichaelTXI only want to copy the title to the weekly summary if there is something between the beginning and terminating delimiters. That's what I meant by:

if (count of parsedList) > 1 then set end of foundItems to originTitle

This isn't working though. Even if there is nothing there (between the two delimiters), it will still copy the title.

Thanks!

Link to comment
  • Level 5*
33 minutes ago, dannyp said:

if (count of parsedList) > 1 then set end of foundItems to originTitle

This isn't working though. Even if there is nothing there (between the two delimiters), it will still copy the title.

How about checking foundItems count instead

Link to comment
  • Level 5*
4 hours ago, dannyp said:

Hmm I'm getting an error:

error "Evernote got an error: Can’t get characters 1 thru 1 of tag \"$ClassNotes\"." number -1728 from characters 1 thru 1of tag "$ClassNotes"

 

3 hours ago, DTLow said:

I need to play around with this
It appears that Applescript doesn't like us using the character/text commands on tags
I think it needs to be converted (coerced) to a string 

This works

set testit to name of theTag as text

        if (text 1 of testit) is not "x" then

 

 

 

tagn : A tag.

elements

contained by application.

properties

name (text) : The tag's name.

parent (tag or missing value) : The tag's parent tag, if any.

responds to

assignunassign.

Link to comment
  • Level 5*
2 hours ago, dannyp said:

@JMichaelTXI only want to copy the title to the weekly summary if there is something between the beginning and terminating delimiters. That's what I meant by:

if (count of parsedList) > 1 then set end of foundItems to originTitle

This isn't working though. Even if there is nothing there (between the two delimiters), it will still copy the title.

Thanks!

Are you using my revised script?  It does NOT do this.  It uses the following IF block:

    if ((count of foundItems) > 0) then ##CHG:  Add IF
      
      ##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

 

Link to comment
  • Level 5*
6 hours ago, dannyp said:

There's a "Created by [name] and shared with [#] people" at the top of every note. Is there no way to access that name?

If your Notes always follow a specific format this might work.  Can you export to ENEX one of your Notes that is a good example, and post to this thread (you may need to zip the file first)?

6 hours ago, dannyp said:

How can I retrieve tags from a note that contain "@" as in "@DP"?

This is easy.  But again, we need a good example.

It would be best to have good examples of:

  1. A source Note to extract the data from
  2. The resultant Summary Note, with the data you want, formatted like you want.

Perhaps you can upload a zip file with two ENEX files of the above.

Link to comment

@JMichaelTX Using the revised script, I still got the title for notes that didn't have content between the two delimiters.

Thank you so much for your help!

 

The following example notes are attached:

A source note with content between delimiters (so I want the title, tag, date, as well as the content between delimiters)

A source note without content between delimiters (so I don't want anything)

A summary note based for content between the first two delimiters

A summary note for content between the last two delimiters

 

Let me know if some other information would be helpful.

Example Notes.enex

Link to comment
  • Level 5*
1 hour ago, dannyp said:

Using the revised script, I still got the title for notes that didn't have content between the two delimiters.

The revised script works for me
Can you attach the actual script file that you're running

With no delimited text, I got an empty summary note

With delimited text (***Test 1!!!), I got the following summary

Text From: Extract Test Template - Class Name B (Updated: Friday, June 10, 2016)
Test 1
 
 
Link to comment
  • Level 5*
27 minutes ago, dannyp said:

 

4 hours ago, dannyp said:

Using the revised script, I still got the title for notes that didn't have content between the two delimiters.

Example Notes.enex

I ran your script and it worked for me

With no delimited text, I got an empty summary note

With delimited text (***Test 1!!!   ***Test 2!!!), I got the following summary

Text From: Extract Test Template - Class Name B (Updated: Friday, June 10, 2016)
Test 1
Test 2
 
and with delimited text in multiple notes
 
Text From: Extract Test Template - Class Name A (Updated: Friday, June 10, 2016)
Test x

Text From: Extract Test Template - Class Name B (Updated: Friday, June 10, 2016)
Test 1
Test 2
 
Link to comment
  • Level 5*
9 minutes ago, dannyp said:

You got a totally empty summary note? Was a summary note created at all?

I ran the script you provided and got these notes

First Notebook: Weekly Summary Friday, June 10, 2016_1.html

First Notebook: Weekly Summary Friday, June 10, 2016_2.html

First Notebook: Weekly Summary Friday, June 10, 2016_3.html    < Empty 

First Notebook: Weekly Summary Friday, June 10, 2016.html

Link to comment
  • Level 5*
Just now, dannyp said:

Huh. I can't figure it out why the same script would work for you, but not for me. I get the title of the note regardless of whether or not it has delimited content.

Here's a debugging tip.  Add some "Display Dialog xxxx" statements to your script.
This will confirm that you're executing the correct script, and may give you an idea of what is being added to the Found list.

Link to comment
20 hours ago, JMichaelTX said:

Are you using my revised script?  It does NOT do this.  It uses the following IF block:


    if ((count of foundItems) > 0) then ##CHG:  Add IF
      
      ##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

 

I tried using your exact script as well; It still creates a note and incorrectly includes the title even though nothing exists between the delimiters (see attached).

Versioning? Some difference by business notebook?

Screen Shot 2016-06-10 at 3.58.49 PM.png

Screen Shot 2016-06-10 at 3.59.22 PM.png

Link to comment
  • Level 5*
6 minutes ago, zrandall said:

I tried using your exact script as well; It still creates a note and incorrectly includes the title even though nothing exists between the delimiters (see attached).

Versioning? Some difference by business notebook?

Screen Shot 2016-06-10 at 3.58.49 PM.png

Screen Shot 2016-06-10 at 3.59.22 PM.png

I see; you're adding the delimiters, with no text between them.

I think this could be easily resolved by adding a check for an empty string before

set end of foundItems to item iItem of parsedList
Link to comment
7 minutes ago, DTLow said:

I see; you're adding the delimiters, with no text between them.

I think this could be easily resolved by adding a check for an empty string before


set end of foundItems to item iItem of parsedList

Perfect -- Works for me. dannyp was that your problem too? Assuming you were using some form of header that you'd keep in as a delimiter?

Link to comment
1 hour ago, DTLow said:

I see; you're adding the delimiters, with no text between them.

I think this could be easily resolved by adding a check for an empty string before


set end of foundItems to item iItem of parsedList

That works if I'm checking for just an empty string but in practice I'm looking at a carriage return and can't seem to get it to work. Debugging gives the item in the list as:

</span></div>
<div><span style="font: 12.0px Verdana; font-variant-ligatures: no-common-ligatures">

Thoughts on checking against something like that? Or If it's not an empty string / not a carriage return / is a character (a-z)?

Link to comment
  • Level 5*
4 hours ago, dannyp said:

When I run the exact script that @JMichaelTX provided, I see titles for notes that have no delimited content.

I just tested my script again, and it does NOT show titles of Notes that have no delimited content.

Please double-check the script you are running to be sure it is exactly the script I posted last.

Link to comment
  • Level 5*
4 hours ago, dannyp said:

Huh. I can't figure it out why the same script would work for you, but not for me. I get the title of the note regardless of whether or not it has delimited content.

 

4 hours ago, zrandall said:

I tried using your exact script as well; It still creates a note and incorrectly includes the title even though nothing exists between the delimiters (see attached).

I think both of you are seeing the Note included in the summary when it has the delimiters, but with nothing between the delimiters, like this:
***!!!

So, I will update the above script shortly, to do this:

  1. Exclude empty found items (nothing between delimiters)
  2. Do NOT produce a Summary Report Note if no notes are found with delimiters.
Link to comment
  • Level 5*

Script has been revised in this post:

Revised:  2016-06-10 20:45 CT (Fri)

  • Revised Script (Ver 1.2)
  • ADDED:  Exclude empty found items (nothing between delimiters)
  • CHANGED:  Do NOT produce a Summary Report Note  if no notes are found with delimiters.
    • If no notes are found, a popup dialog is displayed, so stating.
Link to comment
10 hours ago, JMichaelTX said:

Script has been revised in this post:

Revised:  2016-06-10 20:45 CT (Fri)

  • Revised Script (Ver 1.2)
  • ADDED:  Exclude empty found items (nothing between delimiters)
  • CHANGED:  Do NOT produce a Summary Report Note  if no notes are found with delimiters.
    • If no notes are found, a popup dialog is displayed, so stating.

Thanks JMichael -- the not producing a note when no notes found works great.

I tried to get at this above but here's a bit more context. In the check to see if it's nothing is between the delimiters (""), if you type just the delimiters and run it it works great. However, try the following steps and see if it still works?

1) Type the delimiters

2) Carriage return in between the delimiters

3) Erase the carriage return you just typed between the delimiters (thus bringing it back to an empty string so your check should work)

4) Run script

Does this produce the same results for you? I get it checking against a not null string (</span></span><span style="font-size: 12px;"><span style="font-family: Verdana;">)

Note: I would actually want to keep the carriage return in place and have the script ensure there is text between, not just an empty string or one/set of carriage returns. I'm just observing that it's checking against other pieces such as font if there is a carriage return and/or there was at some point a carriage return.

Link to comment
  • Level 5*
On June 11, 2016 at 5:47 AM, zrandall said:

Note: I would actually want to keep the carriage return in place and have the script ensure there is text between, not just an empty string or one/set of carriage returns. I'm just observing that it's checking against other pieces such as font if there is a carriage return and/or there was at some point a carriage return.

The latest changes bypass an empty string, and you can add a bypass for the "default" text
As to other underlying html text, perhaps you should look for a process to convert the entry to pure text.

I saw this code at Veritrope (http://veritrope.com/code/evernote-get-plain-text-of-selected-note/)
set plain_Text to do shell script "echo " & quoted form of the_HTML & space & "| textutil  -convert txt  -stdin -stdout"
Reference: http://www.unix.com/man-page/osx/1/textutil/

Edit:

The above code doesn't specify an input format

It would be more accurate to specify      textutil -format html ........

Link to comment
  • Level 5*
8 hours ago, DTLow said:

As to other underlying html text, perhaps you should look for a process to convert the entry to pure text.

My script already does this.  The extraction of text is done using the plain text of the Note.

Link to comment
  • Level 5*
9 hours ago, zrandall said:

However, try the following steps and see if it still works?

1) Type the delimiters

2) Carriage return in between the delimiters

3) Erase the carriage return you just typed between the delimiters (thus bringing it back to an empty string so your check should work)

4) Run script

Does this produce the same results for you?

I just ran this test, and it worked as expected:  Nothing was included from the Note that used the above process, which results in an empty result between delimiters.

Just to be clear, when you say "Erase the carriage return", I simply placed the cursor at the start of the new line with the second delimiter, and pressed the DELETE (backspace) key.

So, I am unable to reproduce the issue you are reporting.

Link to comment
On June 11, 2016 at 5:08 PM, JMichaelTX said:

I just ran this test, and it worked as expected:  Nothing was included from the Note that used the above process, which results in an empty result between delimiters.

Just to be clear, when you say "Erase the carriage return", I simply placed the cursor at the start of the new line with the second delimiter, and pressed the DELETE (backspace) key.

So, I am unable to reproduce the issue you are reporting.

If you run it against the attached note does it work? This still gives me a note with title etc. If I look at what it's finding (i.e. not the null string), it looks like

</span></span><span style="font-size: 12px;"><span style="font-family: Verdana;">

Sample Note.enex

Link to comment
On 6/10/2016 at 8:54 PM, JMichaelTX said:

Script has been revised in this post:

Revised:  2016-06-10 20:45 CT (Fri)

  • Revised Script (Ver 1.2)
  • ADDED:  Exclude empty found items (nothing between delimiters)
  • CHANGED:  Do NOT produce a Summary Report Note  if no notes are found with delimiters.
    • If no notes are found, a popup dialog is displayed, so stating.

I'm using this updated script and having the same error as @zrandall. I get the title even if there's nothing between the delimiters.

Ultimately, I also want to omit the title if the only content between the delimiters is a return.

Link to comment
  • Level 5*
7 hours ago, zrandall said:

If you run it against the attached note does it work? This still gives me a note with title etc. If I look at what it's finding (i.e. not the null string), it looks like

</span></span><span style="font-size: 12px;"><span style="font-family: Verdana;">

A bug was causing the HTML to not be properly converted to plain text.  Fixed.

4 hours ago, dannyp said:

I'm using this updated script and having the same error as @zrandall. I get the title even if there's nothing between the delimiters.

Ultimately, I also want to omit the title if the only content between the delimiters is a return.

New version posted to Github Gist that should fix both issues reported above:
EN Mac Create Note from Text in Delimiters.applescript

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
Link to comment
2 hours ago, JMichaelTX said:

A bug was causing the HTML to not be properly converted to plain text.  Fixed.

New version posted to Github Gist that should fix both issues reported above:
EN Mac Create Note from Text in Delimiters.applescript


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

@JMichaelTX perfect. If only I could double, triple like this whole chain -- so immensely helpful!

Link to comment
18 hours ago, JMichaelTX said:

A bug was causing the HTML to not be properly converted to plain text.  Fixed.

New version posted to Github Gist that should fix both issues reported above:
EN Mac Create Note from Text in Delimiters.applescript


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

Amazing, thank you so much!!

Link to comment
  • Level 5*

@dannyp, @zrandall, and everyone:

I hope you guys will use this as an opportunity to increase your scripting skills.
If you come up with any cool enhancements, please post them here for all to enjoy.

There is much that can be done with EN Mac using AppleScript or JavaScript for Automation (JXA).

Link to comment
15 hours ago, JMichaelTX said:

@dannyp, @zrandall, and everyone:

I hope you guys will use this as an opportunity to increase your scripting skills.
If you come up with any cool enhancements, please post them here for all to enjoy.

There is much that can be done with EN Mac using AppleScript or JavaScript for Automation (JXA).

@JMichaelTX Am looking to do just that!

Hopefully I get it working (And will post an update if successful), but I'm looking at formatting the output more cleanly (e.g. keeping bullets, returns, etc. intact).

Link to comment
  • Level 5*

Hey guys, I'm working on a major update that uses the HTML text, so it can copy nice HTML formatted text (between the delimiters) to the new note.

Here's a sneak preview.  Should be ready in a day or so.

Comments?  Suggestions?

EN-Mac-6.7.1-Example-Note-Extract-Text-V

EN-Mac-6.7.1-Example-Note-Summary-V2.png

 

Link to comment
On June 15, 2016 at 6:57 PM, JMichaelTX said:

Hey guys, I'm working on a major update that uses the HTML text, so it can copy nice HTML formatted text (between the delimiters) to the new note.

Here's a sneak preview.  Should be ready in a day or so.

Comments?  Suggestions?

EN-Mac-6.7.1-Example-Note-Extract-Text-V

EN-Mac-6.7.1-Example-Note-Summary-V2.png

Wow - Looks great, @JMichaelTX - Excited to see  the updated version! That's exactly how you would want it (viz. keeping source formatting)

Link to comment
  • Level 5*

>>Debugging gives the item in the list as:</span></div>
     <div><span style="font: 12.0px Verdana; font-variant-ligatures: no-common-ligatures">

>>As to other underlying html text, perhaps you should look for a process to convert
     the entry to pure text.

On June 11, 2016 at 2:57 PM, JMichaelTX said:

My script already does this.  The extraction of text is done using the plain text of the Note.

I see it; your script applies this at the beginning of the extract
Your updated version should solve the "bypass empty extract" requirement

My suggestion was to apply this conversion for the "bypass empty extract" test
My preference is to leave the extracted text intact

Link to comment
  • Level 5*
On 6/17/2016 at 6:23 AM, zrandall said:

Wow - Looks great, @JMichaelTX - Excited to see  the updated version! That's exactly how you would want it (viz. keeping source formatting)

Great, glad you like it.  It's going to take a bit longer that I thought, because, I'm add the following:

  1. Performance optimization -- I'm finding that with a large number of notes in a Notebook, it is taking longer than I want
  2. Error checking to exclude notes with unbalanced delimiters.
  3. More Script Setup options, like these:

----------------------------------------------------
### ~~~~~~~~~~~~~~ SCRIPT SETUP ~~~~~~~~~~~~~~
----------------------------------------------------
-- Change the below properties to suit your needs
-- If there are any other custom properties you'd like, please post.

--- NOTEBOOK TO BE SEARCHED FOR DELIMITED TEXT ---
property prNBName : "Archive" -- "TestExtractText"

--- TAG LIST TO BE ASSIGNED TO NEW NOTE ---
--    • Set to "" for no tags
--    • Tag will be created if it does not exist
property prTagListNewNote : {"TEST", "Test_Script"} -- Example:  {"TEST", "Test_Script"}

--- DELIMITER USED IN NOTES ---
property prBeginDelim : "***" -- beginning delimiter
property prEndDelim : "!!!" -- ending delimiter

--- OUPUT CHOICES ---
property prOpenNewNoteBol : true -- Set to true to Open New Note in Window
property prPrefixTextListStr : "" -- "Source Note: "  -- Prefix of Each Delim Text List

--- OUTPUT OF LAST UPDATE STRING ---
property prOutputDateStr : "tooltip" -- Set to "yes", "no", "tooltip"
property prPrefixDateStr : "LU: " -- whatever you want: "Last Update: ", "Updated: ", etc

--- TITLE OF NEW NOTE ---  (whatever you'd like)
property prNewNoteTitle : prNBName & ": Summary as of " & date string of (current date)

### ~~~~~~~~~~ END OF SCRIPT SETUP ~~~~~~~~~~~~~~~~~

Link to comment
  • 4 weeks later...
On June 19, 2016 at 0:07 AM, JMichaelTX said:

Great, glad you like it.  It's going to take a bit longer that I thought, because, I'm add the following:

  1. Performance optimization -- I'm finding that with a large number of notes in a Notebook, it is taking longer than I want
  2. Error checking to exclude notes with unbalanced delimiters.
  3. More Script Setup options, like these:

----------------------------------------------------
### ~~~~~~~~~~~~~~ SCRIPT SETUP ~~~~~~~~~~~~~~
----------------------------------------------------
-- Change the below properties to suit your needs
-- If there are any other custom properties you'd like, please post.

--- NOTEBOOK TO BE SEARCHED FOR DELIMITED TEXT ---
property prNBName : "Archive" -- "TestExtractText"

--- TAG LIST TO BE ASSIGNED TO NEW NOTE ---
--    • Set to "" for no tags
--    • Tag will be created if it does not exist
property prTagListNewNote : {"TEST", "Test_Script"} -- Example:  {"TEST", "Test_Script"}

--- DELIMITER USED IN NOTES ---
property prBeginDelim : "***" -- beginning delimiter
property prEndDelim : "!!!" -- ending delimiter

--- OUPUT CHOICES ---
property prOpenNewNoteBol : true -- Set to true to Open New Note in Window
property prPrefixTextListStr : "" -- "Source Note: "  -- Prefix of Each Delim Text List

--- OUTPUT OF LAST UPDATE STRING ---
property prOutputDateStr : "tooltip" -- Set to "yes", "no", "tooltip"
property prPrefixDateStr : "LU: " -- whatever you want: "Last Update: ", "Updated: ", etc

--- TITLE OF NEW NOTE ---  (whatever you'd like)
property prNewNoteTitle : prNBName & ": Summary as of " & date string of (current date)

### ~~~~~~~~~~ END OF SCRIPT SETUP ~~~~~~~~~~~~~~~~~

 

@JMichaelTX -- how's the update going? My project was temporarily put on hold, but I was thinking about it today and was curious if you'd had any more progress.

Link to comment
  • Level 5*
15 minutes ago, zrandall said:

@JMichaelTX -- how's the update going? My project was temporarily put on hold, but I was thinking about it today and was curious if you'd had any more progress.

Sorry it is taking so long.  This project got put on hold due to other pressing  tasks.  Hopefully I can finish this script and publish it within the next week.  If you don't hear from me by then, feel free to ping me again.  

Link to comment
  • 3 weeks later...
On July 15, 2016 at 4:15 PM, JMichaelTX said:

Sorry it is taking so long.  This project got put on hold due to other pressing  tasks.  Hopefully I can finish this script and publish it within the next week.  If you don't hear from me by then, feel free to ping me again.  

Just wanted to check in again and see if you had anything else on this -- thanks, @JMichaelTX!!

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...