Hello people, im using this script to save incomming mail attachment’s to a folder
on my desktop, and i have a script to save all incomming mail to the same folder,
when i save a email it will be saved like this " account@host_date " now what i need
is to do the same with the attachment… " attachment_date " im pretty new in applescript
so i dont have a clue on what to do…
using terms from application "Mail"
on perform mail action with messages The_Messages
set Save_folder to SaveFolder()
tell application "Mail" to repeat with This_Message in The_Messages
repeat with ma from 1 to (count every mail attachment of This_Message)
set save_file to (Save_folder & (the name of mail attachment ma of This_Message))
save mail attachment ma of This_Message in save_file
end repeat
end repeat
end perform mail action with messages
end using terms from
---------------------------------------------------------------------
on SaveFolder()
set a to "OS X:Users:mkh:Desktop:Mailfiles:"
end SaveFolder
property Save_folder : (path to desktop as string) & "Mailfiles:"
using terms from application "Mail"
on perform mail action with messages The_Messages
tell application "Mail"
repeat with This_Message in The_Messages
if (count mail attachments of This_Message) > 0 then
repeat with ma in mail attachments of This_Message
save ma in (Save_folder & name of ma)
end repeat
end if
end repeat
end tell
end perform mail action with messages
end using terms from
O.K. this is a bit more complicated, because you have to extract name and extension from the attachment,
and there could be either no extension or more than one comma in the filename.
Note: I haven’t tested what’s happening, if the final filename is longer than 31 characters
property Save_folder : (path to desktop as string) & "Mailfiles:"
using terms from application "Mail"
on perform mail action with messages The_Messages
tell application "Mail"
repeat with This_Message in The_Messages
if (count mail attachments of This_Message) > 0 then
repeat with ma in mail attachments of This_Message
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "."}
set ma_name to name of ma
if (count text items of ma_name) = 1 then
set {fName, fExt} to {ma_name, ""}
else if (count text items of ma_name) = 2 then
set {fName, fExt} to text items of ma_name
else
set {fName, fExt} to {text items 1 thru -2 of ma_name as text, last text item of ma_name}
end if
set AppleScript's text item delimiters to ASTID
tell (current date) to set theDate to short date string
set Save_file to fName & "_" & theDate
if fExt is not "" then set Save_file to Save_file & "." & fExt
save ma in (Save_folder & Save_file)
end repeat
end if
end repeat
end tell
end perform mail action with messages
end using terms from