Wednesday, August 10, 2022

#1 2009-06-18 10:26:21 am

philwood
Member
Registered: 2009-06-18
Posts: 2

Help with Script: Import Mail to Devonthink will NOT import attachment

First, I am rather new to Applescript, so forgive my ignorance. 

I am using Devonthink Office Pro for organizing and capturing my workflow and I have set up two applescripts to import mail into Devonthink: one on command and one as a Rule.  I set up a separate mail account so that any message coming into that account will be automatically imported to devonthink inbox and deleted from the Mail App.  This way I can use my iphone and other computers to send thought or ideas to my Devonthink inbox.  It works great, however it will not import any attachments into the devonthink inbox with the mail message.  It simply leaves them behind and they get deleted in the Mail Rule.  I contacted Devonthink and they said the script needs to be modified or changed. 

Please help!  I am copying two scripts below for you to see what is possibly missing and where I could add it to make it work.  Let me know what you think.

1) This script is for the Mail Rule to import Mail when it arrives in Mail inbox:

Applescript:


-- Mail Rule Action Import to DEVONthink Pro.
-- Created by Christian Grunenberg on Mon Apr 19 2004.
-- Copyright (c) 2004-2009. All rights reserved.

-- this string is used when the message subject is empty
property pNoSubjectString : "(no subject)"

using terms from application "Mail"
   on perform mail action with messages theMessages for rule theRule
       tell application "Mail"
           repeat with theMessage in theMessages
               my importMessage(theMessage)
           end repeat
       end tell
   end perform mail action with messages
end using terms from

on importMessage(theMessage)
   tell application "Mail"
       try
           set theDateReceived to the date received of theMessage
           set theDateSent to the date sent of theMessage
           set theSender to the sender of theMessage
           set theSubject to subject of theMessage
           if theSubject is equal to "" then set theSubject to pNoSubjectString
           set theSource to the source of theMessage
           set theReadFlag to the read status of theMessage
           tell application id "com.devon-technologies.thinkpro2"
               set theRecord to create record with {name:theSubject & ".eml", type:unknown, creation date:theDateSent, modification date:theDateReceived, URL:theSender, source:(theSource as string)} in incoming group
               set unread of theRecord to (not theReadFlag)
           end tell
       end try
   end tell
end importMessage

2) The other one below is to import on Command from the scripts menu:

Applescript:



-- Import selected Mail messages to DEVONthink Pro.
-- Created by Christian Grunenberg on Mon Apr 19 2004.
-- Copyright (c) 2004-2009. All rights reserved.

-- this string is used when the message subject is empty
property pNoSubjectString : "(no subject)"

tell application "Mail"
   try
       tell application id "com.devon-technologies.thinkpro2"
           if not (exists current database) then error "No database is in use."
       end tell
       set theSelection to the selection
       if the length of theSelection is less than 1 then error "One or more messages must be selected."
       repeat with theMessage in theSelection
           my importMessage(theMessage)
       end repeat
   on error error_message number error_number
       if error_number is not -128 then display alert "Mail" message error_message as warning
   end try
end tell

on importMessage(theMessage)
   tell application "Mail"
       try
           set theDateReceived to the date received of theMessage
           set theDateSent to the date sent of theMessage
           set theSender to the sender of theMessage
           set theSubject to subject of theMessage
           if theSubject is equal to "" then set theSubject to pNoSubjectString
           set theSource to the source of theMessage
           set theReadFlag to the read status of theMessage
           tell application id "com.devon-technologies.thinkpro2"
               set theRecord to create record with {name:theSubject & ".eml", type:unknown, creation date:theDateSent, modification date:theDateReceived, URL:theSender, source:(theSource as string)} in incoming group
               set unread of theRecord to (not theReadFlag)
           end tell
       on error error_message number error_number
           if error_number is not -128 then display alert "Mail" message error_message as warning
       end try
   end tell
end importMessage

If you have any advice, it would be greatly appreciated!
thanks!

phil

Model: MacBook Pro 2.2 Ghz Intel, 2 GB Ram
AppleScript: 2.0.1
Browser: Safari 528.17
Operating System: Mac OS X (10.5)


Filed under: Script, mail, DEVONthink, import

Offline

 

#2 2009-06-18 10:43:30 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11771
Website

Re: Help with Script: Import Mail to Devonthink will NOT import attachment

Hi,

of course the attachments won't be saved, because there are no commands in the script to do this.
I don't use Devonthink so I have no idea which kind of data the application expects.
Normally to use the attachments you have to save them somewhere on disk

This is a sample rule to save attachments into a specified folder

Applescript:


property destinationFolder : "Data:path:to:Folder:"

using terms from application "Mail"
   on perform mail action with messages theMessages
       repeat with oneMessage in theMessages
           repeat with oneAttachment in mail attachments of oneMessage
               save oneAttachment in destinationFolder & (get name of oneAttachment)
           end repeat
       end repeat
   end perform mail action with messages
end using terms from

Last edited by StefanK (2009-06-18 10:44:13 am)


regards

Stefan

Offline

 

#3 2009-06-18 10:52:35 am

philwood
Member
Registered: 2009-06-18
Posts: 2

Re: Help with Script: Import Mail to Devonthink will NOT import attachment

Thanks Stefan,

I did notice that there was no mention of the attachment in the script.  I just don't know how to add the lines of code to the attachment.

Devonthink will take any file type into its database.  How could I take your code and add it to the mail rule script to make it import the attachment into the database?  Would i just put it at the bottom and make the destination :    tell application id "com.devon-technologies.thinkpro2"?

phil

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)