I used an AppleScript as a Mail rule under Snow Leopard, and now that I have upgraded to Lion, this AppleScript does not run anymore with Mail.app 5.
This script is run as a Mail Rule, each time there is an incoming message with one or multiple PDF or JPG as attachment(s).
It extracts the attachment(s) to a directory and gives an unique file name based on the date/time.
It seems to be a problem with compatibility between Mail.app 4 and Mail.app 5 so it should not be difficult to resolve.
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
set dt to path to desktop
set outputPath to (dt as rich text) & "Incoming OCR:"
set x to 1
repeat with thisMessage in theMessages
tell mail attachments of thisMessage to set {attachs, cnt} to {it, count it}
set y to 1
repeat with thisItem in attachs
try
if MIME type of thisItem is "application/pdf" and file size of thisItem > 11000 then
tell ((date received of thisMessage) as «class isot» as string) to ¬
tell ((date received of thisMessage) as «class isot» as string) to ¬
rich text 1 thru 4 & "-" & rich text 6 thru 7 & "-" & rich text 9 thru 10 & "-" & ¬
rich text 12 thru 13 & "." & rich text 15 thru 16 & "." & rich text 18 thru 19
save thisItem in (outputPath & result & "-#" & x & "-" & y & ".pdf")
set y to y + 1
end if
if MIME type of thisItem is "image/jpeg" and file size of thisItem > 11000 then
tell ((date received of thisMessage) as «class isot» as string) to ¬
tell ((date received of thisMessage) as «class isot» as string) to ¬
rich text 1 thru 4 & "-" & rich text 6 thru 7 & "-" & rich text 9 thru 10 & "-" & ¬
rich text 12 thru 13 & "." & rich text 15 thru 16 & "." & rich text 18 thru 19
save thisItem in (outputPath & result & "-#" & x & "-" & y & ".jpg")
set y to y + 1
end if
end try
end repeat
set x to x + 1
end repeat
end perform mail action with messages
end using terms from
Model: iMac
AppleScript: 2.4
Browser: Safari 534.48.3
Operating System: Mac OS X (10.7)