Path to attachment folder

Hello,

Is it possible to retrieve the path to the attachments folder? I want to set a variable to a path to any file attachment that comes in an email. I know can set the variable to the attachment, move it and then get the path to its new location, but can I get the path of its original location?

Like this:
set temp to alias “Macintosh HD:Users:mbust:Library:Containers:com.apple.mail:Data:Library:Mail Downloads:0E1C8C1A-EF37-4634-8B2A-A1D7430925DA:somefile.pdf”

and do this for any file in an email message?

Thanks.

Not the most elegant thing in the world.

The Message ID, which is retrievable from Applescript, is stored in the Spotlight-accessible “Where From” field of the attachment.

This is working for me, and the run time is only < 0.02 seconds, and I have about 10 GB of mail.


tell application "Mail" to set messageID to the message id of item 1 of (get selection)
set attachmentsPath to quoted form of ((POSIX path of (path to library folder from user domain)) & "Containers/com.apple.mail/Data/Library/Mail Downloads/")
set theAttachmentPaths to paragraphs of (do shell script "mdfind -onlyin " & attachmentsPath & " \"kMDItemWhereFroms == '*" & messageID & "*'\"")
set allAttachmentPaths to {}
repeat with aPath in theAttachmentPaths
	tell application "Finder" to set attachmentFolder to the parent of ((POSIX file (contents of aPath)) as alias)
	copy attachmentFolder to end of allAttachmentPaths
end repeat

Thank you! I will give it a try!