• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: about your problem with attachments
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: about your problem with attachments


  • Subject: Re: about your problem with attachments
  • From: Yvan KOENIG <email@hidden>
  • Date: Wed, 04 Jan 2017 14:14:17 +0100

I made complementary tests. We aren't forced to ask the script to store the files in the downloads folder, we may use a subfolder so we have now a complete workaround.

--------------------------------------------------------------------------------
set folderName to "attachments" # Change the name if you wish
set downloadFolder to (path to downloads folder as text) # Don't change this instruction
set attachmentsFolder to downloadFolder & folderName & ":" # Don't remove the ending colon
tell application "System Events"
if not (exists folder attachmentsFolder) then
make new folder at end of folder downloadFolder with properties {name:folderName}
end if
end tell

tell application "Mail"
set selectedMessages to every message of mailbox "aaa" # Of course, it's just an example


repeat with theMessage in selectedMessages
repeat with theAttachment in theMessage's mail attachments
set PosixName to name of theAttachment
# CAUTION, if the name of the file contain some slashes,
# it replace them by colons. So the next instruction reset the slashs.
set originalName to my remplace(PosixName, ":", "/")
set savePath to attachmentsFolder & originalName
try
save theAttachment in file (savePath)
end try
end repeat
end repeat


end tell

#=====
(*
replaces every occurences of d1 by d2 in the text t
*)
on remplace(t, d1, d2)
local oTIDs, l
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d1}
set l to text items of t
set AppleScript's text item delimiters to d2
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end remplace

--------------------------------------------------------------------------------

If the attachmentsFolder didn't existed at first execution the script creates it.
Once it's done, we may attach a folder action script to this folder so that it moves the files to the folder of our choice in which - at this time - we can't store them directly.

Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) mercredi 4 janvier 2017 14:13:31


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Re: about your problem with attachments (From: Brian Christmas <email@hidden>)
 >Re: about your problem with attachments (From: Yvan KOENIG <email@hidden>)
 >Re: about your problem with attachments (From: Brian Christmas <email@hidden>)
 >Re: about your problem with attachments (From: Yvan KOENIG <email@hidden>)
 >Re: about your problem with attachments (From: Brian Christmas <email@hidden>)
 >Re: about your problem with attachments (From: Yvan KOENIG <email@hidden>)

  • Prev by Date: Re: about your problem with attachments
  • Next by Date: Re: about your problem with attachments
  • Previous by thread: Re: about your problem with attachments
  • Next by thread: Re: about your problem with attachments
  • Index(es):
    • Date
    • Thread