Description
The handler can be called to get the details of an item in Evernote.The Code
on getEvernote_Info(theNotes)
tell application "Evernote"
try
set noteID to (local id of item 1 of theNotes)
set noteName to (title of item 1 of theNotes)
set noteSource to (source URL of item 1 of theNotes)
set noteCreated to (creation date of item 1 of theNotes)
set noteModified to (modification date of item 1 of theNotes)
set noteTags to (tags of item 1 of theNotes)
set noteAttachments to {attachments of item 1 of theNotes}
set noteAltitude to (altitude of item 1 of theNotes)
set noteENML to (ENML content of item 1 of theNotes)
set noteHTML to (HTML content of item 1 of theNotes)
set noteLat to (latitude of item 1 of theNotes)
set noteLong to (longitude of item 1 of theNotes)
set noteNotebook to (name of notebook of item 1 of theNotes)
set noteLink to (note link of item 1 of theNotes)
end try
end tell
end getEvernote_Info
tell application "Evernote"
try
set noteID to (local id of item 1 of theNotes)
set noteName to (title of item 1 of theNotes)
set noteSource to (source URL of item 1 of theNotes)
set noteCreated to (creation date of item 1 of theNotes)
set noteModified to (modification date of item 1 of theNotes)
set noteTags to (tags of item 1 of theNotes)
set noteAttachments to {attachments of item 1 of theNotes}
set noteAltitude to (altitude of item 1 of theNotes)
set noteENML to (ENML content of item 1 of theNotes)
set noteHTML to (HTML content of item 1 of theNotes)
set noteLat to (latitude of item 1 of theNotes)
set noteLong to (longitude of item 1 of theNotes)
set noteNotebook to (name of notebook of item 1 of theNotes)
set noteLink to (note link of item 1 of theNotes)
end try
end tell
end getEvernote_Info
This doesn’t get ALL the note properties – the Author property is missing!
Right now, Evernote isn’t exposing the author property through AppleScript…
I’ll update my code as soon as they update theirs! 😀
Here’s another question –
How did you get “TheNotes” in the first place? I’m trying to figure out how you can get any notes from the “selection”. I know you can get notes from a notebook, but how do you get them from “selection”?
Thanks!
This bit of code is a subroutine — One way to tell is that these begin with “ON” and they usually live at the end of a larger AppleScript. Subroutines are useful ways to organize and easily reuse your code (which is why I put this together for anyone to drop into their own scripts that need to work with Evernote items).
To use a subroutine, you could do something like this:
set theNotes to selection
set noteInfo to my getEvernote_Info(theNotes)
end tell
Sometimes, it’s easier for people to understand how code works if it isn’t contained in a subroutine. Here’s an example of the above code integrated directly with the subroutine code:
set theNotes to selection
try
set noteID to (local id of item 1 of theNotes)
set noteName to (title of item 1 of theNotes)
set noteSource to (source URL of item 1 of theNotes)
set noteCreated to (creation date of item 1 of theNotes)
set noteModified to (modification date of item 1 of theNotes)
set noteTags to (tags of item 1 of theNotes)
set noteAttachments to {attachments of item 1 of theNotes}
set noteAltitude to (altitude of item 1 of theNotes)
set noteENML to (ENML content of item 1 of theNotes)
set noteHTML to (HTML content of item 1 of theNotes)
set noteLat to (latitude of item 1 of theNotes)
set noteLong to (longitude of item 1 of theNotes)
set noteNotebook to (name of notebook of item 1 of theNotes)
end try
end tell
Hi Justin I’m trying to rename notes (& attachments) to selected text in note. I could do it but I’d like to rename the attach accordingly to selected text AND file extension: do you have an idea on how to get the second (file extension)?. Thanks! Here’s my code, don’t know how to define the type or extension of the attached file(s):
tell application "System Events"
keystroke "c" using command down
tell application "Evernote"
set myNote to selection
set title of item 1 of myNote to (the clipboard as text)
--set myFileType to ??????
set filename of attachment of item 1 of myNote to (the clipboard as text) & myFiletype
end tell
end tell
Hi Edoardo,
Here’s some sample code to give you some ideas!
tell application "System Events"
keystroke "c" using command down
tell application "Evernote"
set myNote to selection
set title of item 1 of myNote to (the clipboard as text)
set nameFile to (filename of attachment of item 1 of myNote)
--USE TEXT ITEM DELIMITERS TO PULL OUT EXTENSION
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"."}
set extFile to (second text item of item 1 of nameFile)
set AppleScript's text item delimiters to saveTID
--ANOTHER METHOD: GETTING MIME TYPE
set typeMIME to (mime of attachment 1 of item 1 of myNote)
--YOU WOULD PUT IN A LIST OF EXTENSIONS CORRESPONDING TO MIME TYPES HERE…
-- (E.G., if typeMIME is "application/pdf" then set extFile to "pdf")
--CHANGE THE FILENAME…
set filename of attachment of item 1 of myNote to (the clipboard as text) & "." & extFile
end tell
end tell
Thanks Justin,
I had thought using TID but, as I’m not a script-minja I thought there were more ‘elegant’ solution…but finally I think it’s the easiest way of doing it…I’ve added an “if…else” clause to check if the note has attachments to avoid errors in the script. Thanks again