Jump to content

Applescript: linking Apple's Mail messages into Evernote


Recommended Posts

Hi, following a discussion requesting the ability to link Apple Mail messages into Evernote, I post this applescript.

The procedure is:

  1. select an evernote Note (target)
  2. select one or more message(s) in Apple's Mail
  3. run the script.

Link(s) will be created in the selected Evernote Note pointing to the Mail message(s).

The link will work on any other mac having the same Mail account and even on iOS devices (provided the message is one of the most recent ones).

Feel free to use it and modify at your convenience.

set _links to {}

set _Titles to {}

set _dates to {}

 

tell application "Mail"

    set _sel to get selection

    repeat with _msg in _sel

        set _messageURL to "message:\\%3c" & _msg's message id & "%3e"

        set end of _links to _messageURL

        set myTitle to the subject of _msg

        set end of _Titles to myTitle

        set theDate to date received of _msg

        set theString to ((time string of theDate) & " " & (day of theDate) as string) & " " & (month of theDate) as string

        set theAuthor to sender of _msg

        set theString to theString & " - " & theAuthor & " -   "

        set end of _dates to theString

    end repeat

    set AppleScript's text item delimiters to return

    set the clipboard to (_links as string)

end tell

 

tell application "Evernote"

    activate

    try

        set theNotes to selection

        repeat with thisNote in theNotes

            set theHTML to HTML content of thisNote

            repeat with n from 1 to count of _links

                set _messageURL to item n of _links

                set theTitle to item n of _Titles

                set theDate to item n of _dates

                -- append thisNote html "<div><b><a href=" & _messageURL & ">" & theTitle & "</a></b></div>"

                set theHTML to "<div><b>" & theDate & "   <a href=" & _messageURL & ">" & theTitle & "</a></b></div>" & theHTML

                set HTML content of thisNote to theHTML

            end repeat

        end repeat

    end try

end tell

 

 

 

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...