Entourage to Evernote Applescript

UPDATED ON JANUARY 24, 2012

This AppleScript has been updated and moved into the Veritrope.com Code Library!

18 Responses to “Entourage to Evernote Applescript”

  1. rob cherny May 31, 2009 at 7:13 pm #

    Hey, great scripts! The Entourage script is a great idea since it doesn’t support native import. Also, seems to work quite well, however I seem to always get an error at the top of the note:

    Error Screenshot

    The messages import fine, I just always get that message, something to do with a semi-colon.

    thanks for making these public!

    • Justin May 31, 2009 at 8:04 pm #

      Glad you like them!

      I have a guess as to why you’re getting that message based on some things I discovered about Evernote while developing subsequent scripts….

      I’ll take some time and play around with a few changes in the code. In the interim, is there anything in the emails that you suspect would be a “common denominator” (especially typographic symbols like colons, commas, semi-colons, etc.)?

      Kind Regards,

      Justin

      • rob cherny June 2, 2009 at 9:26 am #

        Hey not off hand. But the last couple tests I ran were fine, so I’m not sure if it was just a more complicated message or what. I sent some “Plain Text” and some “Rich Text” versions to myself and they imported just fine, so maybe they’re edge cases?

        I’ll keep trying and let you know if I find something more consistent.

        thanks again!

  2. Pete November 17, 2009 at 7:23 am #

    Hi Justin,

    thank you very much for your script Entourage into Evernote. Really a nice piece of work.

    Currently I have the need to clip not only the email body but as well the attachements into Evernote. Browsed the AppleScript library for the Evernote Mac Client, but it seems there is currently no support to generate a note containing (several) attachements plus some text.

    So decided to do some workaround and patch your AppleScript. It now creates individual notes one with the email body (just like yours) and one for each attachement in the email. I then combine the notes manually into a single note after inspecting and removing any unwanted attachments (aka logos etc.). Not a single click solution, but works for me quite well.

    The script temporarily writes the attachements to your disk. I’ve hardcoded the destination to a folder named tmp inside your user folder. You have to create it before you can use the script (or change the script). The saved attachements in tmp are automatically deleted once they are imported into Evernote.

    Feel free to add this to your script repository and make changes.

    Have fun.

    Pete

    Here is the source:

    (*
    http://veritrope.com
    Entourage to Evernote
    Version 1.1
    Nov 17, 2009

    Modified by Peter Gutbrod to add clipping of email attachments.

    Project Status, Latest Updates, and Comments Collected at:
    http://veritrope.com/tips/entourage-to-evernote

        Some choices inspired by the following scripts/authors:
        -- Mike Hall (http://mph.puddingbowl.org/)
        -- Ernie Soffronoff
        -- Daniel N. Byler's DEVONthink script
        -- NetNewsWire To Pukka and Yojimbo
        -- Jan Erik Mostrom's script
        -- David Nunez scripts
        -- MANY, MANY OTHERS!

    Installation:  A few options....

    -- You can highlight the email messages you want to archive into Evernote and double-click this script file;
    -- You can save this script to ~/Documents/Microsoft User Data folder or simply drag the script into the Entourage Script Menu Items folder and it is immediately available for use.
    -- Keyboard shortcuts can also be assigned to AppleScripts in the script menu using the System Preferences "Keyboard & Mouse Settings".

    FastScripts Installation (Optional, but recommended):
    -- Download and Install FastScripts from http://www.red-sweater.com/fastscripts/index.html
    -- Save this script to ~/Library/Scripts/Applications/Microsoft Entourage
    -- Set up your keyboard shortcut in FastScripts Preferences
    *)

    property successCount : 0
    property MailTitle : ""
    property EVTag : ""
    property myTitle : ""

    (* CHECK FOR GROWL *)
    tell application "System Events"
        set processnames to name of every process
    end tell
    if "GrowlHelperApp" is in processnames then
        tell application "GrowlHelperApp"
            set the allNotificationsList to {"Success Notification", "Failure Notification"}
            set the enabledNotificationsList to {"Success Notification", "Failure Notification"}
            register as application ¬
                "Entourage to Evernote" all notifications allNotificationsList ¬
                default notifications enabledNotificationsList ¬
                icon of application "Evernote"
        end tell
    end if

    tell application "Finder"
        set TmpFolder to ((folder "tmp" of home) as text)
    end tell

    (*MAIN PROGRAM *)
    tell application "Microsoft Entourage"
        try
            if (selection is not 0) then
                set defaultTag to "Email Message"
                set userInput to ¬
                    text returned of ¬
                    (display dialog "Enter Tags, separated by colons or commas:" & return & return & ¬
                        "NOTE: Default Tag is 'Email Message'" default answer defaultTag)
                set theDelims to {":", ","}
                set EVTag to my Tag_List(userInput, theDelims)
                set theMessages to current messages
                set EVnotebook to my Notebook_List()
                repeat with thisMessage in theMessages
                    set myTitle to the subject of thisMessage
                    set myContent to the content of thisMessage
                    set ReplyAddr to the sender's address of thisMessage
                    set EmailDate to the time received of thisMessage
                    set myText to "Message from mailto:" & ReplyAddr & " on " & EmailDate & ":" & return & return & myContent

                    tell application "Evernote"
                        set n to create note with text myText ¬
                            title myTitle ¬
                            notebook ¬
                            EVnotebook tags EVTag
                        set creation date of n to EmailDate
                        set source URL of n to ReplyAddr
                    end tell

                    set theAttachments to the attachments of thisMessage
                    repeat with thisAttachment in theAttachments
                        set theName to name of thisAttachment
                        set FilePath to TmpFolder & theName
                        save thisAttachment in FilePath

                        tell application "Evernote"
                            set n to create note from file FilePath ¬
                                notebook EVnotebook tags EVTag
                            set creation date of n to EmailDate
                            set source URL of n to ReplyAddr
                        end tell
                        tell application "Finder"
                            delete file FilePath
                        end tell
                    end repeat
                    set successCount to successCount + 1
                end repeat

                if "GrowlHelperApp" is in processnames then
                    tell application "GrowlHelperApp" -- GROWL SUCCESS
                        notify with name ¬
                            "Success Notification" title ¬
                            "Import Success" description "Successfully Exported " & successCount & ¬
                            " Messages to Evernote!" application name "Entourage to Evernote"
                    end tell
                    set successCount to 0
                end if

            else if "GrowlHelperApp" is in processnames then
                tell application "GrowlHelperApp" -- GROWL FAILURE FOR NO SELECTION
                    notify with name ¬
                        "Failure Notification" title ¬
                        "Import Failure" description ¬
                        "No headline or tab selected!" application name "Entourage to Evernote"
                end tell

            else if "GrowlHelperApp" is not in processnames then -- NON-GROWL ERROR MSG. FOR NO SELECTION
                display dialog "No headline or tab selected!" with icon 0
            end if

            (* ERROR HANDLING *)
        on error errText number errNum
            if "GrowlHelperApp" is in processnames then
                tell application "GrowlHelperApp" -- GROWL FAILURE FOR ERROR
                    notify with name ¬
                        "Failure Notification" title ¬
                        "Import Failure" description "Failed to export " & return & myTitle & ¬
                        ""  due to the following error: " & return & errText ¬
                        application name "Entourage to Evernote"
                end tell
            else if "GrowlHelperApp" is not in processnames then -- NON-GROWL ERROR MSG. FOR ERROR
                display dialog "Item Failed to Import: " & errNum & return & errText with icon 0
            end if
        end try
    end tell

    (* SUBROUTINES *)
    --TAG SELECTION SUBROUTINE
    on Tag_List(userInput, theDelims)
        set oldDelims to AppleScript's text item delimiters
        set theList to {userInput}
        repeat with aDelim in theDelims
            set AppleScript's text item delimiters to aDelim
            set newList to {}
            repeat with anItem in theList
                set newList to newList & text items of anItem
            end repeat
            set theList to newList
        end repeat
        return theList
        set AppleScript's text item delimiters to oldDelims
    end Tag_List

    --EVERNOTE NOTEBOOK SELECTION SUBROUTINE
    on Notebook_List()
        tell application "Evernote"
            activate
            set listOfNotebooks to {} (*PREPARE TO GET EVERNOTE'S LIST OF NOTEBOOKS *)

            (*GET THE NOTEBOOK LIST *)
            set EVNotebooks to every notebook
            repeat with currentNotebook in EVNotebooks
                set currentNotebookName to (the name of currentNotebook)
                copy currentNotebookName to the end of listOfNotebooks
            end repeat

            (*SORT THE LIST *)
            set Folders_sorted to my simple_sort(listOfNotebooks)

            (*USER SELECTION FROM NOTEBOOK LIST *)
            set SelNotebook to choose from list of Folders_sorted with title "Select Evernote Notebook" with prompt ¬
                "Current Evernote Notebooks" OK button name "OK" cancel button name "New Notebook"

            if (SelNotebook is false) then (*CREATE NEW NOTEBOOK OPTION *)
                set userInput to ¬
                    text returned of (display dialog "Enter New Notebook Name:" default answer "")
                set EVnotebook to userInput
            else
                set EVnotebook to item 1 of SelNotebook
            end if

        end tell
    end Notebook_List

    --SORT SUBROUTINE
    on simple_sort(my_list)
        set the index_list to {}
        set the sorted_list to {}
        repeat (the number of items in my_list) times
            set the low_item to ""
            repeat with i from 1 to (number of items in my_list)
                if i is not in the index_list then
                    set this_item to item i of my_list as text
                    if the low_item is "" then
                        set the low_item to this_item
                        set the low_item_index to i
                    else if this_item comes before the low_item then
                        set the low_item to this_item
                        set the low_item_index to i
                    end if
                end if
            end repeat
            set the end of sorted_list to the low_item
            set the end of the index_list to the low_item_index
        end repeat
        return the sorted_list
    end simple_sort
    • Justin November 17, 2009 at 11:42 am #

      Hi Peter,

      By publishing the source code, I had hoped to encourage people to do what you have done — Great Job! 😀

      Your fellow users (including me!) can thank you for an additional option to work with our attachments. (I moved your comment here to the script’s page so that Entourage users would be more likely to find it.)

      An update on the script itself: I am in the middle of a pretty substantial rewrite of many of these scripts to include, among other things, moving email attachments into Evernote. Anyone interested in testing them should sign up for the email list on Veritrope and I’ll contact you when a “sneak preview build” is ready.

      And in the meantime, anyone who wants to make changes or suggestions is welcome to do so here!

      • Pete November 17, 2009 at 11:57 am #

        Thanks Justin.

        My additions are small in compare to your whole script. Nice to hear you are working on a rewrite. I’m interested to hear, how you work around the limitations of the AppleScript implementation in the current Evernote client. So of cause I’ll subscribe to your beta list. 😉

  3. Pete November 17, 2009 at 12:45 pm #

    Btw. I’ve ran into the same error message rob cherny mentioned on a few emails.

    I’ve tracked it down to:

    set myContent to ""
    tell application "Evernote"
        set n to create note with text myContent
    end tell

    Tried to find, what combination of slash and greater/lesser triggers the error in Evernote, but didn’t find a logic.

    Post as well on Evernote forum, probably some developers have a clue.

    • Justin November 17, 2009 at 1:56 pm #

      Yeah — My guess is that the “text parser” chokes on anything that looks like XML/HTML while creating the note.

      However, it works fine if you create the note using HTML. Here is a version of your sample code that does this (modified to be valid HTML):

      set myContent to "<a href="http://veritrope.com/" rel="nofollow">Veritrope.com</a>"
      tell application "Evernote"
          set n to create note with html myContent
      end tell

      The note is successfully created with a clickable URL in the body.

      I’ve run into this type of problem with the titles of the notes and put in some code that stripped-out some troublesome typography. Clearly though, this isn’t as workable of a solution for the note body — an AppleScript like this shouldn’t modify people’s content, in my opinion.

      I have some ideas to work-around but, really, I’d like to get some sense from the Evernote development team if some changes/bug fixes are coming in the near future. Let’s be sure to ask about it in the AppleScript thread there.

      • Pete November 18, 2009 at 7:58 am #

        Hi Justin,

        it is not ideal to mess with body of a note, but the following modification of your script gets rid of the error message:

        repeat with thisMessage in theMessages
            set myTitle to the subject of thisMessage
            set myContent to the content of thisMessage
            set myContent to do shell script "echo " &amp; quoted form of myContent &amp; " | sed 's/\&lt;[^//g'"

        At least a workaround until Evernote improves their text parser.

        Below the changes incorporated into my initial mods of your script for the lazy people. 😉

        Have fun.

        Pete

        (*
        http://veritrope.com
        Entourage to Evernote
        Version 1.1
        Nov 17, 2009

        Modified by Peter Gutbrod to add clipping of email attachments.

        Project Status, Latest Updates, and Comments Collected at:
        http://veritrope.com/tips/entourage-to-evernote

            Some choices inspired by the following scripts/authors:
            -- Mike Hall (http://mph.puddingbowl.org/)
            -- Ernie Soffronoff
            -- Daniel N. Byler's DEVONthink script
            -- NetNewsWire To Pukka and Yojimbo
            -- Jan Erik Mostrom's script
            -- David Nunez scripts
            -- MANY, MANY OTHERS!

        Installation:  A few options....

        -- You can highlight the email messages you want to archive into Evernote and double-click this script file;
        -- You can save this script to ~/Documents/Microsoft User Data folder or simply drag the script into the Entourage Script Menu Items folder and it is immediately available for use.
        -- Keyboard shortcuts can also be assigned to AppleScripts in the script menu using the System Preferences "Keyboard &amp; Mouse Settings".

        FastScripts Installation (Optional, but recommended):
        -- Download and Install FastScripts from http://www.red-sweater.com/fastscripts/index.html
        -- Save this script to ~/Library/Scripts/Applications/Microsoft Entourage
        -- Set up your keyboard shortcut in FastScripts Preferences
        *)

        property successCount : 0
        property MailTitle : ""
        property EVTag : ""
        property myTitle : ""

        (* CHECK FOR GROWL *)
        tell application "System Events"
            set processnames to name of every process
        end tell
        if "GrowlHelperApp" is in processnames then
            tell application "GrowlHelperApp"
                set the allNotificationsList to {"Success Notification", "Failure Notification"}
                set the enabledNotificationsList to {"Success Notification", "Failure Notification"}
                register as application ¬
                    "Entourage to Evernote" all notifications allNotificationsList ¬
                    default notifications enabledNotificationsList ¬
                    icon of application "Evernote"
            end tell
        end if

        tell application "Finder"
            set TmpFolder to ((folder "tmp" of home) as text)
        end tell

        (*MAIN PROGRAM *)
        tell application "Microsoft Entourage"
            try
                if (selection is not 0) then
                    set defaultTag to "Email Message"
                    set userInput to ¬
                        text returned of ¬
                        (display dialog "Enter Tags, separated by colons or commas:" &amp; return &amp; return &amp; ¬
                            "NOTE: Default Tag is 'Email Message'" default answer defaultTag)
                    set theDelims to {":", ","}
                    set EVTag to my Tag_List(userInput, theDelims)
                    set theMessages to current messages
                    set EVnotebook to my Notebook_List()
                    repeat with thisMessage in theMessages
                        set myTitle to the subject of thisMessage
                        set myContent to the content of thisMessage
                        set myContent to do shell script "echo " &amp; quoted form of myContent &amp; " | sed 's/\&lt;[^//g'"
                        set ReplyAddr to the sender's address of thisMessage
                        set EmailDate to the time received of thisMessage
                        set myText to "Message from mailto:" &amp; ReplyAddr &amp; " on " &amp; EmailDate &amp; ":" &amp; return &amp; return &amp; myContent

                        tell application "Evernote"
                            set n to create note with text myText ¬
                                title myTitle ¬
                                notebook ¬
                                EVnotebook tags EVTag
                            set creation date of n to EmailDate
                            set source URL of n to ReplyAddr
                        end tell

                        set theAttachments to the attachments of thisMessage
                        repeat with thisAttachment in theAttachments
                            set theName to name of thisAttachment
                            set FilePath to TmpFolder &amp; theName
                            save thisAttachment in FilePath

                            tell application "Evernote"
                                set n to create note from file FilePath ¬
                                    notebook EVnotebook tags EVTag
                                set creation date of n to EmailDate
                                set source URL of n to ReplyAddr
                            end tell
                            tell application "Finder"
                                delete file FilePath
                            end tell
                        end repeat
                        set successCount to successCount + 1
                    end repeat

                    if "GrowlHelperApp" is in processnames then
                        tell application "GrowlHelperApp" -- GROWL SUCCESS
                            notify with name ¬
                                "Success Notification" title ¬
                                "Import Success" description "Successfully Exported " &amp; successCount &amp; ¬
                                " Messages to Evernote!" application name "Entourage to Evernote"
                        end tell
                        set successCount to 0
                    end if

                else if "GrowlHelperApp" is in processnames then
                    tell application "GrowlHelperApp" -- GROWL FAILURE FOR NO SELECTION
                        notify with name ¬
                            "Failure Notification" title ¬
                            "Import Failure" description ¬
                            "No headline or tab selected!" application name "Entourage to Evernote"
                    end tell

                else if "GrowlHelperApp" is not in processnames then -- NON-GROWL ERROR MSG. FOR NO SELECTION
                    display dialog "No headline or tab selected!" with icon 0
                end if

                (* ERROR HANDLING *)
            on error errText number errNum
                if "GrowlHelperApp" is in processnames then
                    tell application "GrowlHelperApp" -- GROWL FAILURE FOR ERROR
                        notify with name ¬
                            "Failure Notification" title ¬
                            "Import Failure" description "Failed to export " &amp; return &amp; myTitle &amp; ¬
                            ""  due to the following error: " &amp; return &amp; errText ¬
                            application name "Entourage to Evernote"
                    end tell
                else if "GrowlHelperApp" is not in processnames then -- NON-GROWL ERROR MSG. FOR ERROR
                    display dialog "Item Failed to Import: " &amp; errNum &amp; return &amp; errText with icon 0
                end if
            end try
        end tell

        (* SUBROUTINES *)
        --TAG SELECTION SUBROUTINE
        on Tag_List(userInput, theDelims)
            set oldDelims to AppleScript's text item delimiters
            set theList to {userInput}
            repeat with aDelim in theDelims
                set AppleScript's text item delimiters to aDelim
                set newList to {}
                repeat with anItem in theList
                    set newList to newList &amp; text items of anItem
                end repeat
                set theList to newList
            end repeat
            return theList
            set AppleScript's text item delimiters to oldDelims
        end Tag_List

        --EVERNOTE NOTEBOOK SELECTION SUBROUTINE
        on Notebook_List()
            tell application "Evernote"
                activate
                set listOfNotebooks to {} (*PREPARE TO GET EVERNOTE'S LIST OF NOTEBOOKS *)

                (*GET THE NOTEBOOK LIST *)
                set EVNotebooks to every notebook
                repeat with currentNotebook in EVNotebooks
                    set currentNotebookName to (the name of currentNotebook)
                    copy currentNotebookName to the end of listOfNotebooks
                end repeat

                (*SORT THE LIST *)
                set Folders_sorted to my simple_sort(listOfNotebooks)

                (*USER SELECTION FROM NOTEBOOK LIST *)
                set SelNotebook to choose from list of Folders_sorted with title "Select Evernote Notebook" with prompt ¬
                    "Current Evernote Notebooks" OK button name "OK" cancel button name "New Notebook"

                if (SelNotebook is false) then (*CREATE NEW NOTEBOOK OPTION *)
                    set userInput to ¬
                        text returned of (display dialog "Enter New Notebook Name:" default answer "")
                    set EVnotebook to userInput
                else
                    set EVnotebook to item 1 of SelNotebook
                end if

            end tell
        end Notebook_List

        --SORT SUBROUTINE
        on simple_sort(my_list)
            set the index_list to {}
            set the sorted_list to {}
            repeat (the number of items in my_list) times
                set the low_item to ""
                repeat with i from 1 to (number of items in my_list)
                    if i is not in the index_list then
                        set this_item to item i of my_list as text
                        if the low_item is "" then
                            set the low_item to this_item
                            set the low_item_index to i
                        else if this_item comes before the low_item then
                            set the low_item to this_item
                            set the low_item_index to i
                        end if
                    end if
                end repeat
                set the end of sorted_list to the low_item
                set the end of the index_list to the low_item_index
            end repeat
  4. Pete November 18, 2009 at 8:15 am #

    Ar more conservative version would be

    set myContent to do shell script "echo " &amp; quoted form of myContent &amp; " | sed 's/\&lt;[^//g'"

    just stripping the / from the closing /> tag

    • Pete November 18, 2009 at 8:17 am #

      Upps wrong copy/paste. 😉

      set myContent to do shell script "echo " &amp; quoted form of myContent &amp; " | sed -E 's/(\&lt;[^)/\1\2/g'"
      • Justin November 18, 2009 at 11:41 am #

        To be very clear about what this is for people just joining the thread (and for those new to AppleScript):

        • Pete’s modified code will create one note for the email message body and and additional note for each attachment to that email. You can then manually merge these items into a single note if you’d like
        • Pete’s modification to the script will remove certain typography from your note body in order to avoid a specific type of error. If keeping the typographical symbols inside your notes unchanged is important to you, you shouldn’t use this code.

        Thanks for your hard work and for posting this, Pete!

  5. bmar May 19, 2011 at 6:12 pm #

    Hi, I would really love to find a way to export Entrourage – or Outlook for mac “Notes” (not emails or contact or calendar entries – only the “Notes”) into Evernote – does anyone know how this can be done?
    Thanks, bmar

  6. James Harrison August 8, 2011 at 6:10 am #

    Followed your instructions to the letter but the script does not appear in the Entourage script menu. (Downloaded, moved to Entourage Script Menu Items… and nothing appears)

    I presume I don’t need to reboot? I did restart Entourage but it made no difference.

    Any ideas would be useful!

    James

    Entourage version: 12.2.9
    Evernote version 2.1.0

    iMac
    Intel Core 2 Duo
    3.06 GHz
    Number Of Processors: 1
    Total Number Of Cores: 2
    L2 Cache: 3 MB
    Memory: 4 GB

    • Justin Lancy August 8, 2011 at 10:05 am #

      Hmmm… that is weird!

      If this was happening to me, I think I’d try renaming the script according to these instructions. My hope would be that this would force Entourage to detect it and, at the same time, activating a keyboard shortcut to run the script.