Created
May 24, 2022 12:51
-
-
Save RosemaryOrchard/e6d96eefd173f0991dd0128254e9d8d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use AppleScript version "2.4" -- Yosemite (10.10) or later | |
use scripting additions | |
using terms from application "Mail" | |
on perform mail action with messages theMessages for rule theRule | |
-- The folder to save the attachments in (must already exist) | |
set attachmentsFolder to ((path to home folder) & "Documents:Attachments") as string | |
-- Save in a sub-folder based on the name of the rule in Mail | |
set subFolder to name of theRule as string | |
tell application "Finder" | |
if not (exists folder subFolder of folder attachmentsFolder) then | |
make new folder at attachmentsFolder with properties {name:subFolder} | |
end if | |
end tell | |
tell application "Mail" | |
repeat with eachMessage in theMessages | |
-- Get the date the message was sent | |
set dateStamp to do shell script "date +%Y-%m-%d" | |
repeat with theAttachment in eachMessage's mail attachments | |
set originalName to name of theAttachment | |
set savePath to attachmentsFolder & ":" & subFolder & ":" & dateStamp & " " & originalName | |
-- try | |
save theAttachment in file (savePath) with replacing | |
-- end try | |
end repeat | |
-- delete message | |
delete eachMessage | |
end repeat | |
end tell | |
end perform mail action with messages | |
end using terms from |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment