Evernote Tag Checker Subroutine


This subroutine will take the text value of a tag name (or a list of tag names) and process them so that they're ready to be used in your AppleScript. Here's how it works -- When you pass tags through this code (the variable is called "theTags" in my example), the handler checks to see if each tag already exists. If it already does, it adds it to the final tag list. If it doesn't, it will first create it before adding it to a list. The script then takes that final list of tags and formats it in a way that Evernote's "assign" function can work with the data.

The Code

on Tag_Check(theTags)
    tell application "Evernote"
        set finalTags to {}
        repeat with theTag in theTags
            if (not (tag named theTag exists)) then
                set makeTag to make tag with properties {name:theTag}
                set end of finalTags to makeTag
                set end of finalTags to tag theTag
            end if
        end repeat
    end tell
end Tag_Check