Jump to content

Help with a applescript find notes search using varaible notebook and variable source url


Recommended Posts

Hi, I'm hoping that you can help with a problem I'm really stuck on, given I'm a premium user.  
Im using applescript to automate some tasks, (importing a bunch of files from a tree of directories) and it is working well. However, I need to determine if, as I'm about to upload an additional file, if I've already uploaded it before, within a specific notebook.
 
I'd like to do this based upon having set the "source url" for each note to the location I originally attached the file from.
 
So, as I'm creating a note, with a file attachment, I've set the source url to its path on my Mac.
 
The problem comes when I use the "fine notes" commend with both notebook and sure url as the search string.  Both are variables, which are set depending upon the notebook I'm working in, and the file I want to upload in a note  (or don't want to if already present).
 
I'm having trouble getting the search syntax right.  I've need successful earlier in the script, searching for notes within a notebook, and having specific tags.  However the syntax for the source url search is eluding me... too many quotes and slashes for nested quotes.  its very sensitive to spaces etc. 
 
for example to fine a specifically tagged note within a notebook I used the follow, and it works well....
 
set searchTag to "Attachment_Index_Note"
 
set matches to find notes "notebook:\"" & EVnotebook & "\" tag:\"Attachment_Index_Note\""
 
if matches = {} then
 # no such note
...
else
 # found the note 
...
end if
 
 
Now to my questions...
 
I want to do a similar search, but to see if a note in a notebook (in a variable, as above) with a specific source url (in a variable unlike above) exists.
For example, I've tried...
 

 

set SNotes to {}

tell application "Evernote"

    set SNotes to find notes "notebook:\"" & EVnotebook & "\" source URL: \"" & new_attachment_path & "\"" #<<<---- The Problem Part - syntax

end tell

 

 

# BYPASS STORED FILE Feature 

 

 

if SNotes is equal to {} then # no such file 

... #can make the file.

end if

 

 
Can anyone help with this?
Link to comment
  • Level 5*

 

Hi, I'm hoping that you can help with a problem I'm really stuck on, given I'm a premium user.  
Im using applescript to automate some tasks, (importing a bunch of files from a tree of directories) and it is working well. However, I need to determine if, as I'm about to upload an additional file, if I've already uploaded it before, within a specific notebook.
 
I'd like to do this based upon having set the "source url" for each note to the location I originally attached the file from.
 
So, as I'm creating a note, with a file attachment, I've set the source url to its path on my Mac.
 
The problem comes when I use the "fine notes" commend with both notebook and sure url as the search string.  Both are variables, which are set depending upon the notebook I'm working in, and the file I want to upload in a note  (or don't want to if already present).
 
I'm having trouble getting the search syntax right.  I've need successful earlier in the script, searching for notes within a notebook, and having specific tags.  However the syntax for the source url search is eluding me... too many quotes and slashes for nested quotes.  its very sensitive to spaces etc. 
 
for example to fine a specifically tagged note within a notebook I used the follow, and it works well....
 
set searchTag to "Attachment_Index_Note"
 
set matches to find notes "notebook:\"" & EVnotebook & "\" tag:\"Attachment_Index_Note\""
 
if matches = {} then
 # no such note
...
else
 # found the note 
...
end if
 
 
Now to my questions...
 
I want to do a similar search, but to see if a note in a notebook (in a variable, as above) with a specific source url (in a variable unlike above) exists.
For example, I've tried...
 

 

set SNotes to {}

tell application "Evernote"

    set SNotes to find notes "notebook:\"" & EVnotebook & "\" source URL: \"" & new_attachment_path & "\"" #<<<---- The Problem Part - syntax

end tell

 

 

# BYPASS STORED FILE Feature 

 

 

if SNotes is equal to {} then # no such file 

... #can make the file.

end if

 

 
Can anyone help with this?

 

 

Hi. Welcome to the forums. I moved your thread from the Japanese language developer's forum to the Evernote general discussions. Hopefully, some users familiar with Applescript will be able to help you.

Link to comment

Thanks.. Thats was a good idea.

 

It seems that “source url” is not (yet?) listed officially in Evernote Search Grammar.

 

However, it seems you can utilize sourceurl:*

 

Here it finds notes with a source url but, for some reason, it does not list one note specially.

 

Anyway you can also try a generic note searching e.g.:

tell application id "com.evernote.Evernote"	set x to every note of every notebook whose source URL contains "alfred"end tell 

Finally, check this topic.

Link to comment
  • 1 year later...
  • Level 5*

My thanks to 

 

Anyway you can also try a generic note searching e.g.:

tell application id "com.evernote.Evernote"	set x to every note of every notebook whose source URL contains "alfred"end tell 

 

Thanks Carlos for sharing the basic search for URL text.

 

While your statement ran OK, and returned a list, it wasn't clear how to get the list of actual Notes from it.

It was fairly challenging (for me), but I finally figured it out.

 

Here's the key:

 

--- Returns Compound List of Notebooks and Notes ---

  • a list of Notes within a list of Notebooks
  • All NBs are returned
  • Those without any matching Notes are NULL [{}]

Here's my script, based on Carlos' statement above, that actually runs and outputs a list of Notes and their URLs that match the criteria.

Script file (as a ZIP) is attached to this post at bottom.

 

Please post here, or PM me, if you find any bugs, or have any suggestions.

(*====================================================	How To Search For Text In Evernote Note URL====================================================DATE:  Sat, Nov 14, 2015		VER:  1.0PURPOSE:	• Show how to search for text in the Source URL field	• Show how to find all Notes that meet a critieria using the AppleScript 		every note of every notebook whose <field> <op> <criteria>	• Script currently only outputs Note Title and URL of matching Notes	• You can add further processing as you likeAUTHOR:		JMichael (member of Discussion.Evernote.com forum)				Please PM me with any bugs/issues/questions						INSTALLATION:	•  Copy to your personal Scripts folder:  /Users/<YourName>/Library/Scripts/		(create the Scripts folder if it does not exist)	• To assign shortcut key, use FastScripts or Mac Automator	REF:       FEB 14, 2014====================================================*)property gstrScriptName : "How To Search For Text In Evernote Note URL"tell application "Evernote"		--- Get Compound List of Notebooks and Notes ---	--		Returns a list of Notes within a list of Notebooks	--		All NBs are returned	--		Those without any matching Notes are NULL [{}]		set lstNotesbyNB to every note of every notebook whose source URL contains "macscripter"		set nNumNB to count of lstNotesbyNB	log ("NumNB: " & nNumNB)		display dialog ("Num of NBs to Process:  " & nNumNB) ¬		with title gstrScriptName giving up after 3		---—————————————————————	repeat with iNB from 1 to nNumNB -- Process each NB		set lstNBNotes to item iNB of lstNotesbyNB		----------------------------------------------						if lstNBNotes ≠ {} then -- Skip NB without any matching Notes						set nNumNotes to count of lstNBNotes			log ("NB#: " & iNB & "      NumNotes: " & nNumNotes)						---—————————————————————			repeat with iNote from 1 to nNumNotes -- Process each Note in the NB				set oNote to item iNote of lstNBNotes				----------------------------------------------								if oNote ≠ {} then -- Skip NULL Notes (just in case)										--log "oNote:"					--log oNote										set strNoteTitle to title of oNote					set strURL to source URL of oNote										log ("Note " & iNote & ": " & strNoteTitle)					log ("    URL: " & strURL)										set strMsg to strNoteTitle					set strMSubTitle to "Note #" & iNote & " of " & nNumNotes										display notification strMsg with title gstrScriptName subtitle strMSubTitle										### PUT CODE HERE FOR PROCESSING OF EACH NOTE ###					delay 1 -- just for testing (remove for production)									end if -- oNote ≠ {}							end repeat -- iNote					end if -- lstNBNotes ≠ {}			end repeat -- iNB	---———————————————————————	end tell -- Evernote

How To Search For Text In Evernote Note URL.scpt.zip

Link to comment

Archived

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

×
×
  • Create New...