Importing Mavericks Tags to Evernote

I have a Hazel-based workflow defined for scanned documents. With the release of Mavericks, I added tagging to that flow for things like the company that generated the document, a few tags about what the doc is about (cars, kids, etc). However, I like keeping the docs in Evernote. So, as I usually do, I turned to Applescript and came up with this:

set theActualFile to choose file

set theFile to quoted form of (POSIX path of (theActualFile))

set origDelim to AppleScript’stext item delimiters

set newDelim to “,”

set AppleScript’stext item delimiters to newDelim

— Get tags from file

set userTags to (do shell script “mdls -raw -name kMDItemUserTags ” & theFile)

set theTags to (every text item of userTags)

tell application “Evernote”

set theNote to create note from file theActualFile

–Clean up the list, removing whitespace, quotes, parenthesis, tabs, newlines

repeat with theTag in theTags

— sed command in line below taken from stib’s answer on this page:

set theTag to do shell script “echo ” & quoted form of theTag & “| tr -d ‘\n'”

set theTag to do shell script “echo ” & quoted form of theTag & “| tr -d ‘\r'”

set theTag to do shell script “echo ” & quoted form of theTag & “| tr -d ‘[:blank:]'”

set theTag to do shell script “echo ” & quoted form of theTag & “|sed \”s/[^[:alnum:][:space:]]//g\””

— TODO need to clean out newline as well

if not (tag named theTag exists) then

set my_new_tag to (make new tag with properties {name:theTag})

assign my_new_tag to theNote


assign tag theTag to theNote

end if

end repeat

end tell

set AppleScript’s text item delimiters to origDelim


The workflow asks for a file to be chosen (I’ll fix that so it accepts a file argument later when I’m ready to make it a part of the automated flow), gets the tags as string (via mdls), splits it out, and then strips out the newlines, tabs and whitespace from each of the tags.

Two caveats.

1) I assume it will split apart any tag with a comma in it.
2) It will remove whitespace form inside the tag as well – so a tag of “credit card” will become “creditcard”… but I’m okay with that.

Here’s the Applescript for your downloading pleasure: Import File to Evernote.scpt

4 comments for “Importing Mavericks Tags to Evernote

  1. John
    June 3, 2014 at 2:56 pm

    The applescript you linked to doesn’t work. It looks like you linked to an alias. I would appreciate it if you can share the original script. Thank you!

    • neil
      June 23, 2014 at 9:57 am

      (Sorry for the delay in responding.) Link is updated, go ahead and give it another try.

  2. January 23, 2015 at 2:39 pm

    Can you tell me please how to modify the script to work with selected items in finder instead of prompting for one file?

    • neil
      February 9, 2015 at 10:07 am

      I honestly don’t know; because I use it with Hazel, it’s all one-file-at-a-time. You’d need to tell Finder to get a list of the selected files and then loop through this code for each file.

      It might be easier as a service created with Automator.

Leave a Reply

Your email address will not be published. Required fields are marked *