Entourage to Evernote Applescript

Tags: , , , , ,

Change Log:

  • 1.00 (April 24, 2009) INITIAL RELEASE OF SCRIPT

Okay all you Applescript Ninjas — here’s the code… Dive in, check it out, and tell me how to make it better in the comment thread below!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
(*
http://veritrope.com
Entourage to Evernote
Version 1.0
April 23, 2009

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


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

DOWNLOAD THE SCRIPT FILE


Did this script help you out? Feel free to make a donation!

Want a script customized for your workflow?

Contact me to find out how to commission a script!

Interested in what other scripts are available for Evernote?

Click here to see the latest list!

Entourage to Evernote Applescript

Pages: 1 2

12 Comments / Jump to comment form

12 Responses to “Entourage to Evernote Applescript”

  1. rob cherny rob cherny says:

    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 Justin says:

      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 rob cherny says:

        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 Pete says:

    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:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    (*
    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 Justin says:

      Hi Peter,

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

      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 Pete says:

        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 Pete says:

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

    I’ve tracked it down to:

    1
    2
    3
    4
    set myContent to "<http://veritrope.com/>"
    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 Justin says:

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

      1
      2
      3
      4
      set myContent to "<a href=\"http://veritrope.com/\">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 Pete says:

        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:

        1
        2
        3
        4
        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 " & quoted form of myContent & " | sed 's/\\<[^<]*\\/\\>//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

        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        21
        22
        23
        24
        25
        26
        27
        28
        29
        30
        31
        32
        33
        34
        35
        36
        37
        38
        39
        40
        41
        42
        43
        44
        45
        46
        47
        48
        49
        50
        51
        52
        53
        54
        55
        56
        57
        58
        59
        60
        61
        62
        63
        64
        65
        66
        67
        68
        69
        70
        71
        72
        73
        74
        75
        76
        77
        78
        79
        80
        81
        82
        83
        84
        85
        86
        87
        88
        89
        90
        91
        92
        93
        94
        95
        96
        97
        98
        99
        100
        101
        102
        103
        104
        105
        106
        107
        108
        109
        110
        111
        112
        113
        114
        115
        116
        117
        118
        119
        120
        121
        122
        123
        124
        125
        126
        127
        128
        129
        130
        131
        132
        133
        134
        135
        136
        137
        138
        139
        140
        141
        142
        143
        144
        145
        146
        147
        148
        149
        150
        151
        152
        153
        154
        155
        156
        157
        158
        159
        160
        161
        162
        163
        164
        165
        166
        167
        168
        169
        170
        171
        172
        173
        174
        175
        176
        177
        178
        179
        180
        181
        182
        183
        184
        185
        186
        187
        188
        189
        190
        191
        192
        193
        194
        195
        196
        197
        198
        199
        200
        201
        202
        203
        204
        205
        206
        207
        208
        209
        210
        211
        212
        (*
        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 " & quoted form of myContent & " | sed 's/\\<[^<]*\\/\\>//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 Pete says:

    Ar more conservative version would be

    1
    set myContent to do shell script "echo " & quoted form of myContent & " | sed 's/\\<[^<]*\\/\\>//g'"

    just stripping the / from the closing /> tag

    • Pete Pete says:

      Upps wrong copy/paste. ;-)

      1
      set myContent to do shell script "echo " &amp; quoted form of myContent &amp; " | sed -E 's/(\\&lt;[^)/\\1\\2/g'"
      • Justin Justin says:

        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!

rss Subscribe to Comments RSS Feed


Trackbacks/Pingbacks

  1. Links to Evernote Applescripts and Accessories-- Updated Regularly! | Veritrope
  2. AppleScript: Копирование сообщений Entourage в Evernote | Mac911.Ru

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>