Extracting PDF from Apple Mail - Setting the filename to the date/time


One member (thank you Bruce) has helped me creating an AppleScript for Mail (see under), that extracts PDF files from Mail, and copies them to a directory on the desktop called Incoming PDF with a unique filename.

The name comes as example: Scan-177202-2.pdf

Is there a way that the name of the created .PDF file(s) includes the date/time of the received e-mail ?

YYYYMMDDHHmmss-MessageID-ItemID.pdf where YYYYMMDDHHmmss is the arrival time of the e-mail in my mailbox ?


20081021101845-177202-2.pdf ?

Thanks in advance.

--------------This is the Script---------------
on perform_mail_action(theData)
set outputPath to (path to desktop as Unicode text) & “Incoming PDF:”
set theseMessages to |SelectedMessages| of theData

tell application id “com.apple.mail”
repeat with thisMessage in theseMessages
repeat with thisItem in mail attachments of thisMessage
if MIME type of thisItem is “application/pdf” then
save thisItem in (outputPath & “Scan-” & id of thisMessage & “-” & id of thisItem & “.pdf”)
end if
end try
end repeat
end repeat
end tell
end perform_mail_action

Add this handler to the script:

to GetRightNow()
set n to (current date)
return (n's year & (n's month as number) & n's day & n's hours & n's minutes & n's seconds) as text
end GetRightNow

Then, change your save line to this:

 save thisItem in (outputPath & (my GetRightNow()) & "-Scan-" & id of thisMessage & "-" & id of thisItem & ".pdf")

Good luck,

I’m replying to the original thread: http://bbs.macscripter.net/viewtopic.php?id=27205