Hi,
I am looking for a way of exporting the tags of notes in Evernote to an RTF/CSV file. I have a script that reads/exports all the titles of the notes, but when I try the same with tags I can read the tags, but I’m not sure how to write them to a string/file.
Here is a simple script that reads the tags of a note:
tell application "Evernote"
set the_notes to the selection
set first_note to item 1 of the_notes
set the_tags to (the tags of first_note)
end tell
It returns:
{tag “travel” of application “Evernote”}
But when I try to write this to a TextEdit file by adding:
tell application "TextEdit"
activate
make new document
set theDate to current date
set text of document 1 to the_tags as text
end tell
I get the error: “Can’t make «class EVtg» “travel” of application “Evernote” into type text.”
Could someone help to get the script to write the tags of the notes?
Thanks,
Nick
Hey Nick,
I whipped up this script as a demonstration of how the Evernote AppleScript syntax works for you and our fellow MacScripters!. (I will also mirror a more complete version of it in the Evernote script section of the Veritrope.com Code Library.) It grabs the tags of the currently selected item in Evernote and collects them into a variable which contains a comma-delimited list of tag names (“names_Tags”):
set list_Tags to {}
set names_Tags to ""
tell application "Evernote"
set the_Selection to selection
set list_Tags to tags of (item 1 of the_Selection)
set count_Tags to count of list_Tags
repeat with list_Tag in list_Tags
set the_Name to name of list_Tag
set names_Tags to (names_Tags & the_Name as string)
if count_Tags is greater than 1 then
set names_Tags to (names_Tags & ", " as string)
set count_Tags to (count_Tags - 1)
end if
end repeat
end tell
As you can probably see, the missing piece was that you have to pull the name value from the tag records. Hope this gets you back on track!
Thanks Justin. Very helpful. I have now amended my original script as follows and it seems to do the job:
set h to ""
set list_Tags to {}
set names_Tags to ""
tell application "Evernote"
set the_notes to the selection
repeat with this_note in the_notes
set a to (the title of this_note)
set b to characters 1 thru 4 of a
set c to characters 5 thru 6 of a
set d to characters 7 thru 8 of a
set e to characters ((offset of " " in a) + 1) thru ((offset of "-" in a) - 1) of a
set f to characters ((offset of "-" in a) + 1) thru -1 of a
set names_Tags to ""
set list_Tags to tags of this_note
set count_Tags to count of list_Tags
repeat with list_Tag in list_Tags
set the_Name to name of list_Tag
set names_Tags to (names_Tags & the_Name as string)
if count_Tags is greater than 1 then
set names_Tags to (names_Tags & ", " as string)
set count_Tags to (count_Tags - 1)
end if
end repeat
set g to names_Tags
set h to (h & d & "/" & c & "/" & b & "," & f & ",£" & e & "," & g & return)
end repeat
end tell
set filePath to (path to desktop as text) & "test.csv"
set fp to open for access filePath with write permission
write h to fp
close access fp
Nick