HOWTO mail link from mail to mori?

Tags ( )

Hi,

I know it can be done, but how?

I like to have an applescript that makes an entry in Mori with a link to the corresponding .emlx file from apple mail. If possible with the text of that email. With Mail "act-on" I want to use this to work in GTD-style in Mori.

any help is appreciated

greetings, AJ

Mail-to-Mori

Maybe you can find something in here.
You can, of course, make a file link in Mori to an .emlx file (if you can identify it..). When you click the link, Mail opens that message.
Please describe the workflow you're thinking about.

I'll look into the scripts

I'll look into the scripts tomorrow. The part where the message of the mail is transferred to Mori will most certainly be covered in these scripts.However, the part where the text is tranferred is "the least of my worries".

If an email results in an action in the future, I want to log it in Mori. It would be great to have a link in that entry in Mori which points to the original Emailmessage. Then I can reopen the message and reply to the sender if the action is completed.

So it would go like this?

In Mail, select message.
Run script while still in Mail
Script creates entry in Mori with properties {name:subject_of_msg, note:file_link & content_of_message}
(not a complete list, I'm sure - and pseudocode).

Would you want to add a reminder to the note? I.e., log the action, rather than the message itself?
Take a look at the NoteChan plugin, maybe it allows copy&paste from elsewhere: copy/paste from Mail, add a reminder, done. Copy can be scripted, to get various msg_properties in one go.

The problem is that

The problem is that "file_link" is not a mail-applescript-entity. The script I now use is this one. It makes a new entry (every time) and also displays the date and sender in the note. However, the link to the mailmessage is not included.


property mailedEntryFolderName : "Inbox"
property subjectFlag : ""

using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
repeat with cond in theRule's rule conditions
if cond's rule type is subject header then set subjectFlag to expression of cond
end repeat
tell application "Mail"
repeat with thisMessage in theMessages
--get stuff from mail
set _subject to subject of thisMessage
set _note to content of thisMessage
set _header to all headers of thisMessage
set _date to date received of thisMessage
set _sender to sender of thisMessage

--strip the flag
set saveDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to {subjectFlag}
set theList to every text item of _subject
set AppleScript's text item delimiters to {""}
set _subject to theList as text
set AppleScript's text item delimiters to saveDelim

--add entry to Mori in folder named mailedEntryFolderName of root entry
tell application "Mori"
tell front document
--create folder for mailed entries if it doesn't exist
if not (exists entry named mailedEntryFolderName of root entry) then
make new entry with properties {name:INBOX, «class MIct»:"public.folder"}
end if

set newEntry to make new entry at end of entries of (entry named mailedEntryFolderName of root entry) with properties {name:_subject, note:"From: " & _sender & return & "Date: " & _date & return & return & _note}
end tell
end tell
end repeat
end tell
end perform mail action with messages
end using terms from

File links are brittle

They don't follow the target file around when it is moved.
Same goes for links to Mail msgs: when msg is moved within Mail, the corresponding .emlx file gets moved on disk, and the link breaks.

As it happens I just posted a script that provides a workaround. Take a look.

It should be perfectly possible to script creation of a link in Mori, even when the script is started in Mail.
The problem is finding the .emlx file. Here's class "document" in the Standard Suite of Mail's AppleScript dictionary:

document : A document.
properties
path (string) : The document's path.
modified (boolean, r/o) : Has the document been modified since the last save?
name (string) : The document's name.

Can do?

No can do

Well, I double-clicked a message in Mail, and then ran this little script in Script Editor:
tell application "Mail"
properties of front window
end tell

This is the result:
{zoomed:false, miniaturized:false, name:"Re: Support Form Submission: Suggestion", floating:false, modal:false, document:missing value, miniaturizable:true, class:window, visible:true, closeable:true, resizable:true, zoomable:true, id:6150, bounds:{397, 22, 1277, 899}, titled:false, index:1}

As you can see, document is a missing value. Mail does not want to tell us where the msg files are.

Find Mail message through metadata

This just kept bugging me, so I'm happy to report there may be a solution after all.

It could work like this:
Script does Spotlight search on data readable from the selected message: subject, sender, etc.
Note that only one message should be returned; must figure out how to achive this.
Then reads kMDItemFSName, which contains name of message file.

So, in practical steps to a solution:
A
Look at AppleScript properties of messages, and select a subset that will identify any single message.
This set of properties should also be present in Spotlight metadata.
Script does Spotlight raw query for matching file.
If not doable script should ask to select message from list.

B
Script continues with 'do shell script "mdls ..."' for this message; gets filename from kMDItemFSName.

C
Script proceeds to create file link as previously mentioned. Should use alias method: when you move message in Mail, file also gets moved.

This workflow will show metadata on the selected file. You can copy a line from this list, and paste it into Spotlight's raw query field while you're still in tinkering mode.

Send me a message if you need further help with this.

Automator Actions

I just came across this Automator Action that will do this.

From the source code in the download I find that messages have an AppleScript property 'id', which is the actual filename (without extension).

This problem is now officially solved.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.