Jump to content
Dark Mode is here Read more... ×
  • 0
JMichaelTX

Using AppleScript to Process Tags in EN Mac

Idea

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.

 

Share this post


Link to post

2 replies to this idea

Recommended Posts

  • 0
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.

Share this post


Link to post
  • 0
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!

Share this post


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

×