This script was a request from this thread
[Edit Feb 20 2006: I've added the "pre-built" version of Gordon's script which is a little more refined than the "sendMailToMori" version below, and listed in full in his reply to this thread. You can also find a copy in his script package.]
Basically you can email yourself a message that has the tag "[Mori]" in the subject (with the brackets, but not the quotes) and with the proper mail rule set it will automatically be exported to Mori.
Usage
1. Put this script anywhere.
2. Make a new mail Rule that says: If the subject contains [Mori]; run Applescript sendMailToMori
3. send yourself an email that has [Mori] in the subject
Customizing the script
1. you can change the tag to anything. just change the line that says "property sentTag: "[Mori]"
2. exported messages can be automatically deleted if you uncomment the line for this.
3. alternatively, exported messages can be archived to another mailbox. default is "sentToMori"
Possible improvements:
1. Right now it just sends the message to the front Mori document. It might be possible to chose in advance specifically which document will receive the messages.
2. The script will crash if you have the archive line uncommented, but do not have a mailbox with the expected name.
property sendTag : "[Mori]"
property sentEntriesBox : "sentToMori"
tell application "Mail"
set moriMail to every message of inbox whose subject contains sendTag
repeat with eachItem in moriMail
set subjectLine to the subject of eachItem
set subjectLine to my cleanSubject(subjectLine)
set dateLine to the date sent of eachItem
set notePart to the content of eachItem
try
my sendEntry(subjectLine, dateLine, notePart)
--uncomment the next line if you want the item to be deleted after it is sent
--delete eachItem
--uncomment the next line if you want the item to be moved to a new mailbox after it is exported to Mori. If you're going to use this method, make sure you have a mailbox named the same a the property sentEntriesBox above.
--move eachItem to mailbox sentEntriesBox
end try
end repeat
end tell
on sendEntry(subjectLine, dateLine, notePart)
tell application "Mori"
tell front document
--make sure there's an inbox to receive the new entry
if exists entry named "Inbox" of root entry then
set inFolder to entry named "Inbox" of root entry
else
set inFolder to (make new entry with properties {name:"Inbox", content type:"public.folder"})
end if
make new entry at end of entries of inFolder with properties {name:subjectLine, note:notePart, creation date:dateLine}
end tell
end tell
end sendEntry
on cleanSubject(theText)
--removes sendTag
set saveDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to {sendTag}
set theList to every text item of theText
set AppleScript's text item delimiters to {""}
set theText to theList as text
set AppleScript's text item delimiters to saveDelim
return theText
end cleanSubject
| Attachment | Size |
|---|---|
| sendMailToMori.zip | 4.5 KB |
| Create Entry from Mail Message.scpt.zip | 4.2 KB |
No need to define rule in the script.
I wrote a script yesterday, too, but it was my first time using AppleScript and so it took me until 2am and my eyes closed before I could prepare it for 'prime time' :)
One significant difference, though, which I think is worth using here is the outside of my script:
using terms from application "Mail"
----on perform mail action with messages theMessages
--------tell application "Mail"
------------repeat with eachMessage in theMessages
------------...
------------...
------------end repeat
--------end tell
----end perform mail action with messages
end using terms from
I like this because it applies the script to all messages that meet the rule, so you don't have to define the rule in Mail.app and the same 'rule' in your script.
-- Si Brindley
(I've had a copy of Getting Things Done on my desk for five months and I just got around to starting it.)