Monday, June 18, 2018

#1 2018-05-21 09:00:54 am

Registered: 2011-09-04
Posts: 3

Path to attachment folder


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 Downloads:0E1C8C1A-EF37-4634-8B2A-A1D7430925DA:somefile.pdf"

and do this for any file in an email message?


Filed under: Attachments



#2 2018-06-07 11:33:17 am

From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 258

Re: Path to attachment folder

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/ 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

Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb



#3 2018-06-10 02:15:40 am

Registered: 2011-09-04
Posts: 3

Re: Path to attachment folder

Thank you! I will give it a try!



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)