DT3 provides two ways to send records via e-mail
- with the context menu “Send E-Mail”
- with the smart rule action “Send E-Mail”
These two behave differently: Whereas the first actually sends the record(s?) attached to the e-mail, the second one sends the x-devonthink URL, aka “reference”. It is such pretty much useless outside of the current DT3 installation.
Therefore, I provide the following AppleScript (sic!) to use as an embedded script in smart rules. It has to be adapted before it can be used (recipient, subject and possibly body). The script sends every record as a single attachment in a separate e-mail. If you need one e-mail with all the records attached, you have to modify it slightly.
Also note that there’s a delay 1
in the code. DO NOT REMOVE it. This delay is due to the somewhat imperfect implementation of Apple’s Mail: without the delay, the mail is send before the file is attached to it. It’s a shame that they implement asynchronous operations without a proper mechanism to deal with them, but that’s Apple’s automation…
on performSmartRule(theRecords)
set theReceiver to "" -- ENTER RECEIVER HERE
set theBody to "" -- FILL IN if you need a message text
set theSubject to "Subject" -- ENTER SUBJECT HERE
tell application id "DNtp"
repeat with theRecord in theRecords
sendMail(path of theRecord, theBody, theSubject, theReceiver) of me
end repeat
end tell
end performSmartRule
on sendMail(theFile, theBody, theSubject, theReceiver)
set AppleFile to POSIX file theFile
tell application id "com.apple.mail"
set msg to make new outgoing message with properties {subject:theSubject, content:theBody & return & return}
tell msg
make new to recipient at end of to recipients with properties {address:theReceiver}
make new attachment with properties {file name:AppleFile as alias}
delay 1 -- DO NOT REMOVE!
end tell
send msg
end tell
end sendMail