applescript for extracting attachments from mail
Hi everyone, I'm using this Applescript to extract all attachments from selected Emails:
set p2d to (path to) / Users / x / y / z / as text
tell application "Mail"
set theMessages to the selection
repeat with aMessage in theMessages
set attachCount to count of (mail attachments of aMessage)
if attachCount is not 0 then
tell aMessage
repeat with anAttachment in (mail attachments)
-- check that your system return the name with its extension
set theName to name of anAttachment
tell me to set aFile to (p2d & theName) as «class furl»
save anAttachment in aFile
end repeat
end tell
end if
end repeat
end tell
This works great, except if there are two attachments with the same filename. Then the one saved first gets overwritten by the second.
Can you advise me on how to add code to either prompt me, or automatically add a random string to the file name?
thanks,
geb
MacBook Pro 15″, macOS 10.13