Entourage to Evernote

Description

Mac users who have corporate IT people setting up their computers or who needs full Exchange support often have Microsoft Entourage or the newer Outlook 2011 (part of Microsoft's Office:mac 2011 package) as their email application.

I think Outlook 2011 is a much better Exchange client (with a much better Evernote AppleScript) and, if you're still using Entourage, I'd recommend that you upgrade ASAP! But for those of you who can't, this free script lets you send items directly from Entourage to Evernote with a keystroke and, if you like, even tag and sort them on the way in! GROWL notifications give you status updates as things are added into Evernote.

Adding By Script Vs. Adding By Email

One fast way to get items into Evernote is simply to email them. Brett Kelly's eBook, "Evernote Essentials" provides a solid guide to how this works (See the chapter called "Evernote, Email and You") along with some other great email-related tips. So why not just forward items to your Evernote email address?

You certainly can do that -- but I think this approach is actually easier and also has a few additional benefits:

  • FASTER/SMARTER WORKFLOW. By following the special file-naming convention in the Microsoft Entourage Script Menu (see instructions below), you can use Keyboard Shortcuts that make it incredibly fast and easy to stay organized! Personally, I use ⌘E to quickly send anything to Evernote. I can also tag and direct multiple items to a notebook by using a simple, fast dialog box instead of having to email them in one at a time (Example - Entourage handles multiple emails being forwarded by attaching them as .eml files to a single email). Trust me -- Archiving whole folders goes much faster when you don't have to send an email for every item! But the script isn't just good for big, bulky moves: I can also send less than a whole item, quickly clipping only the bits of highlighted text I'm interested in.

  • NO INTERNET NEEDED. Emailing an item into Evernote probably isn't an option if you have local, non-synchronized notebooks which contain sensitive information (or should you find yourself without an internet connection). This script moves things directly

Features

  • This script exports a text copy of every selected email message in Entourage into Evernote.
  • When the script creates the note in Evernote, it uses the Subject line of the email as the title of the note, and it also uses the date the email was received as the "Creation Date" of the note.
  • The script also copies basic header information to the first line of the note (e.g., a working mailto: link for the message sender and also date/time information).
  • I have added a tag dialog box which lets you tag items on the way into Evernote. If you have selected more than one email, the tag(s) you choose will be applied to all of the messages.
  • The script will also retrieve an alphabetized list of your current Evernote Notebooks and allow you to select which notebook to archive your messages into.
  • Want to make a new notebook? No problem -- the script has a "Create New Notebook" button which will let you do that on the fly!
  • Automatic GROWL detection has also been enabled which will save you a trip to the Script Editor to enable/disable it.

Important Notes and Requirements

  • THIS SCRIPT REQUIRES GROWL. I updated the script to use the newer GROWL app (People with the older, non-App Store version of GROWL can try to do a quick Find-and-Replace on the script, substituting "GrowlHelperApp" for "Growl" wherever it appears in the script.).

  • The script only handles email messages.
  • Text of emails only -- not HTML
  • Email Attachments won't save with the new note.
  • The sender's email address is saved in the "Source URL" section of the note, but Evernote currently only allows http: and https: values to be "valid links" in this space.... so this is currently more "ornamental" than anything else.
  • Entourage is old, so I probably won't be spending any more time on this one!

How to Install and Use

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.

You can highlight the email messages you want to archive into Evernote and then double-click this script file, or trigger it via a keyboard shortcut. Give it a filename that enables a keyboard shortcut to be used.

Example: "Send to EvernotemE.scpt" lets you press ⌘E to send items to Evernote!

Enjoy!

The Code

(*
Veritrope.com
Microsoft Entourage to Evernote
Version 1.1
January 24, 2012

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

// CHANGELOG:

1.1   UPDATED GROWL CODE, IMPROVED TAGGING, REFORMATTED SCRIPT FOR CODE LIBRARY
1.0   INITIAL VERSION

// RECOMMENDED INSTALLATION INSTRUCTIONS:

*)


(*
======================================
// USER SWITCHES
======================================
*)


--SET THIS TO "OFF" IF YOU WANT TO SKIP THE TAGGING/NOTEBOOK DIALOG
--AND SEND ITEMS DIRECTLY INTO YOUR DEFAULT NOTEBOOK
property tagging_Switch : "ON"

--IF YOU'VE DISABLED THE TAGGING/NOTEBOOK DIALOG,
--TYPE THE NAME OF THE NOTEBOOK YOU WANT TO SEND ITEM TO
--BETWEEN THE QUOTES IF IT ISN'T YOUR DEFAULT NOTEBOOK.
--(EMPTY SENDS TO DEFAULT)
property EVnotebook : ""

--IF TAGGING IS ON AND YOU'D LIKE TO CHANGE THE DEFAULT TAG,
--TYPE IT BETWEEN THE QUOTES (ITEM TYPE IS DEFAULT)
property defaultTag : ""

(*
======================================
// OTHER PROPERTIES (USE CAUTION WHEN CHANGING)
======================================
*)


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

(*
======================================
// MAIN PROGRAM
======================================
*)


--CHECK FOR GROWL
tell application "System Events"
    set growlRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
end tell

if growlRunning is true then
    tell application "Growl"
        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 "Microsoft Entourage"
    try
        if (selection is not 0) then
           
            --GET EVERNOTE ACCOUNT INFO
            my account_Check()
           
            --TAGGING?
            if tagging_Switch is "ON" then my tagging_Dialog()
           
            set theMessages to current messages
            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 successCount to successCount + 1
            end repeat
           
            if growlRunning is true then
                tell application "Growl" -- 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 growlRunning is true then
            tell application "Growl" -- 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 growlRunning is not true 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 growlRunning is true then
            tell application "Growl" -- 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 growlRunning is not true 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


(*
======================================
// PREPARATORY SUBROUTINES
======================================
*)

--CHECK ACCOUNT TYPE
on account_Check()
    tell application "
Evernote"
        set account_Info to (properties of account info 1)
        set account_Type to (account type of account_Info) as text
        if EVnotebook is "
" then set EVnotebook to my default_Notebook()
    end tell
end account_Check

(*
======================================
// UTILITY SUBROUTINES
======================================
*)

--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

(*
======================================
// TAGGING SUBROUTINES
======================================
*)

--TAGGING AND NOTEBOOK SELECTION DIALOG
on tagging_Dialog()
    display dialog "
Enter The Tag or Tags Below." & return & ¬
        "
(NOTE: Multiple Tags Should Be Separated By Commas)" with title "Entourage to Evernote Export" default answer defaultTag ¬
        buttons {"
Create in Default Notebook", "Select Notebook from List", "Cancel"} ¬
        default button "
Create in Default Notebook" cancel button ¬
        "
Cancel" with icon path to resource "Evernote.icns" in bundle (path to application "Evernote")
    set dialogresult to the result
    set userInput to text returned of dialogresult
    set ButtonSel to button returned of dialogresult
    set theDelims to {"
,"}
    set userTag to my Tag_List(userInput, theDelims)
    set EVTag to my Tag_Check(userTag)
    if ButtonSel is "
Select Notebook from List" then set EVnotebook to my Notebook_List()
end tagging_Dialog

--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
    set AppleScript's text item delimiters to oldDelims
    return theList
end Tag_List

--CREATES TAGS IF THEY DON'T EXIST
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
            else
                set end of finalTags to tag theTag
            end if
        end repeat
    end tell
    return finalTags
end Tag_Check

--DEFAULT NOTEBOOK FINDER
on default_Notebook()
    tell application "
Evernote"
        set EVnotebook to name of (every notebook whose default is true)
    end tell
end default_Notebook

--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