Jump to content
We apologize for the inconvenience, but chat support is currently unavailable. Please feel free to submit an email ticket or reach out at discussion.evernote.com. Thank you for understanding. ×
  • 0

Using AppleScript to Process Tags in EN Mac


JMichaelTX

Idea

  • Level 5*

Using AppleScript to Process Tags in EN Mac

Continuing the discussion from:

 

@DTLow, I started with your idea and one-line script, and did some testing to determine how to best get all child tags of a parent tag.
Here's what I found:

Your simple script worked, but  it took ~10 sec to run with my 1500+ tags.
So, after some experimentation, I came up with this approach, which  takes on ~0.24 sec:

AppleScript to Get List of Child Tags

property ptyScriptName : "Get List of Child Tags for a Parent Tag"
property ptyScriptVer : "2.0"
property ptyScriptDate : "2018-07-11"
property ptyScriptAuthor : "JMichaelTX"

tell application "Evernote"
  
  ### This Takes about 10 sec for 1500 Tags ###
  
  (*
    set parentTag to tag ".NB.IT"
    set childTagList to name of every tag whose parent is equal to parentTag
  *)
  
  ### This Takes about 0.24 sec ###
  
  set parTagName to ".NB.IT"
  set tagNameList to name of every tag
  set parNameList to name of parent of every tag
  set childTagList to {}
  
  repeat with iTag from 1 to (count of tagNameList)
    set tagName to item iTag of tagNameList
    set parName to item iTag of parNameList
    
    if (parName = parTagName) then
      set end of childTagList to tagName
    end if
  end repeat
  
  
  
end tell

return childTagList
-->{"SOFTWARE", "IT_List", "Electronics", "IT"}

Thanks for sharing your complete script to get the list, and to do a recursive process to get all lower child tags.
I'll take a look at that and see if it also can be optimized.

38 minutes ago, DTLow said:

So it's just a matter if composing variable  searchQuery 
For multiple tags, it would be      any:   tag:Tag1   tag:Tag2 ...

So that would give us  a  list of Notes that were assigned any of the child tags.  Unfortunately it  would not allow any other Search criteria (like dates, inTitle, other tags), which the EN Win search will allow.

 

  • Thanks 1
Link to post

18 replies to this idea

Recommended Posts

  • 0
  • Level 5*
On 7/11/2018 at 6:24 PM, JMichaelTX said:

Unfortunately it  would not allow any other Search criteria (like dates, inTitle, other tags), which the EN Win search will allow.

Confirmed, the search feature does not allow for combination And/Or searches.

My solution is to do multiple searches; assigning a temporary tag to accumulate the search results.

>>Your simple script worked, but  it took ~10 sec to run with my 1500+ tags.
So, after some experimentation, I came up with this approach, which  takes on ~0.24 sec:

Thanks for the timing results, I only have 300 tags but I'll follow up on it. I suspect it's a scale issue.

Link to post
  • 0
  • Level 5*
3 hours ago, JMichaelTX said:

AppleScript to Get List of Child Tags

OK, that script only returns the immediate child tags of the target parent tag.  I now have a proof-of-concept script working that will return all child tags, and descendent tags, down to the lowest level starting with the top-level parent tag.  It is running pretty fast, but I want  to further optimize before I publish.  Turning this into a search is very easy, and the test searches  have been very fast.  Stay tuned for further developments!

Link to post
  • 0

@JMichaelTX I just came across this post.  I'd love to see your script if you feel like sharing.  I'm working to offload some of the front end tasks from evernote the evernote UI is mostly terrible for what I am trying to get done.  to get started, I want to pull out tag and notebook hierarchies into  something like a json file as I am more conversant in python than applescript.   thanks!

Link to post
  • 0
  • Level 5*
16 hours ago, bmat said:

@JMichaelTX I just came across this post.  I'd love to see your script if you feel like sharing. 

. . .
I want to pull out tag and notebook hierarchies into  something like a json file as I am more conversant in python than applescript. 

Did you see my script above?  That should get you started.  I don't have any scripts that create a JSON string from Evernote tags.

 

Link to post
  • 0
  • Level 5*
20 hours ago, bmat said:

I want to pull out tag and notebook hierarchies into  something like a json file

Would a .csv file help
These are tables in a sqlite database1218849492_ScreenShot2020-05-05at11_19_25AM.png.312b5b5280d30834aa9208a7f52ec5c5.png   

My database browser supports export to .csv

Notebook table
- Important  fields are Name and Stack
Tag table  
- Important fields are GUID, Name, ParentGUID

703464415_ScreenShot2020-05-05at11_18_39AM.png.0206fdbba75ba4376efcc3c408ef6cb2.png

Link to post
  • 0

@JMichaelTX thanks.  I did use your script above to get started. many thanks.  I am trying to rebuild the tag hierarchy.  I'm slowly figuring out how to do this in applescript, but applescript is slow, and data structures seem limited, so I may need to figure out how to do this with python instead.  json is a great format for saving this sort of thing as it can take nested lists, key / value lists, etc. as a hack for now, I have applescript write the data to an excel window, but this is also quite slow.

@DTLow thanks as well. I think a csv file would help.  I should be able to import this no problem.

separately, I have been working on pulling note count per notebook and note count per tag.  right now the way I do it is terrible, and like a 30+ minute job.  it involves recursing through notebook by notebook, then note by note to pull the tags from  each note record so that I can ultimately count the number of times each tag shows up (which will involve another set of slow operations).  do you know if there is a better way to get this info out of evernote?

thanks!

 

Link to post
  • 0
  • Level 5*
21 minutes ago, bmat said:

separately, I have been working on pulling note count per notebook and note count per tag

Note count per notebook

tell application "Evernote"
     
set allNotebooks to every notebook
     
repeat with eachNotebook in allNotebooks
          
set notebookName to (the name of eachNotebook)
          
set theNotes to every note in notebook notebookName
          
set theCount to count of theNotes
         
display dialog theCount                    << code for counts
     end repeat
end tell

Link to post
  • 0

@DTLow thanks! I have something like this.  I should have been more specific, its getting the count of notes per tag that has me stuck.   the only way I have found to do this so far is to interrogate each note for the attached tags, put the tags into one list, allowing for duplicate items, and then count the number of duplicates for each tag.  any thoughts to a better way? 

 

btw, if you are curious, https://forum.latenightsw.com/t/writing-json-data-with-nsjsonserialization/1130 talks to converting a list to a json file.

Link to post
  • 0
  • Level 5*
31 minutes ago, bmat said:

its getting the count of notes per tag that has me stuck.

Note count per tag

tell application "Evernote"
     
set allTags to every tag
     
repeat with eachTag in allTags
         
set tagName to (the name of eachTag)
         set theNotes to find notes "tag:\"" & tagName & "\""
         
set theCount to count of theNotes
        
display dialog tagName & theCount           << Code for counts
     
end repeat
end tell

  • Like 1
Link to post
  • 0

 

On 5/5/2020 at 11:26 AM, DTLow said:

Tag table  
- Important fields are GUID, Name, ParentGUID

how do you access GUID and ParentGUID for a tag?

tell application "Evernote"
	set guidList to (the guid of every tag)
end tell

gives an error.

also, is there a way to list the properties that we can interrogate with applescript?  the properties found in https://dev.evernote.com/doc/reference/Types.html don't seem to translate to applescript unless I am referencing them incorrectly.

Link to post
  • 0
  • Level 5*
44 minutes ago, bmat said:

how do you access GUID and ParentGUID for a tag?

I don't work with these fields
As I pointed out above, I can retrieve a csv file from the SQLite database1621314979_ScreenShot2020-05-08at11_21_45AM.png.873a847de33fc45078e8958eaf98be94.png

 

 

 

 

>>is there a way to list the properties that we can interrogate with applescript? 
In Scripte Editor    File > Open Dictionary > Evernote

Screen Shot 2020-05-08 at 11.17.26 AM.png

  • Like 1
Link to post
  • 0
54 minutes ago, DTLow said:

I don't work with these fields
As I pointed out above, I can retrieve a csv file from the SQLite database

AH, got it.  finally caught up to you :).  I should also be able to query this DB directly from python saving some time.  I'll try that one later...  

 

Have you found were the tags are linked to notes?  I didn't see any field for tags in the notes metadata.

 

 

1 hour ago, DTLow said:

In Script Editor    File > Open Dictionary > Evernote

right... thanks.  just getting up to speed on applescript and figuring out what it is good for...

Link to post
  • 0
  • Level 5*
14 minutes ago, bmat said:

Have you found were the tags are linked to notes?  I didn't see any field for tags in the notes metadata.

Because of the note > multiple-tags relationship. a separate table is required
Table name is something like    Tags

>>I should also be able to query this DB directly from python saving some time.  
I query directly from Applescript120456646_ScreenShot2020-05-08at12_32_19PM.png.740abeb4c1959eed4743393375078d3a.png

Link to post
  • 0

looks like this is the one.  filtered off the ID/record#? (not GUID) for the tag and the note. 

image.png.4daffd74eea4fded2a2825af298dd903.png 

also, looks like evernote already caches the note counts for each tag in ZACTIVENOTECOUNT

image.png.9d35372543e2fea4fbd46bd881b320d1.png

 

Thanks for the applescript SQLite query tip. I'll play with it.  Also, curious, what is the ZLOCALUUID vs the ZGUID?

Link to post
  • 0
  • Level 5*
3 hours ago, bmat said:

is there a way to list the properties that we can interrogate with applescript?

Yes.  Open the Script Editor.app, and then open the Evernote Dictionary by menu File > Open Dictionary, and choose "Evernote.app"

There is a search box, where you can type "note" to see the Note properties, and "tag" to see tag properties.  You want the "tag class" or "note class".  Looks like this:

2020-05-08_16-09-41.png.884e00de94cb02e3f490ef3243006aa3.png

 

Link to post
  • 0
  • Level 5*

BTW guys, if you are going to do much AppleScript work, then I highly recommend Script Debugger 7 .  It provides a great IDE for development, exploring the scripting object models, real-time display of variables, and of course great full-featured debugging.

  • Like 1
Link to post
  • 0
  • Level 5*
12 hours ago, bmat said:

Thanks for the applescript SQLite query tip. I'll play with it.  Also, curious, what is the ZLOCALUUID vs the ZGUID?

On a Mac, note contents are stored outside of the database; a separate folder for each note   
EverNote tracks the folder name, stored in the database as  Localuuid

  • Like 1
Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...