Created
September 21, 2012 11:53
-
-
Save nst/3761057 to your computer and use it in GitHub Desktop.
Save attachments of selected messages in OS X Mail.app, mark the messages as read.
This file contains hidden or 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
-- file: mail_save_attachments.txt | |
-- author: Nicolas Seriot | |
-- date: 2012-09-18 | |
-- description: save attachments of selected messages in mail, mark the messages as read | |
-- usage: $ osascript mail_save_attachments.txt /some/directory | |
on run parameters | |
using terms from application "Mail" | |
set saveDirectory to item 1 of parameters | |
tell application "Mail" to set theSelectedMessages to selection | |
repeat with theMessage in theSelectedMessages | |
set theID to id of theMessage | |
repeat with theAttachment in theMessage's mail attachment | |
set theAttachmentFileName to saveDirectory & "/" & theID & "-" & theAttachment's name | |
log "-- saving " & theAttachmentFileName | |
save theAttachment in POSIX file theAttachmentFileName | |
end repeat | |
set read status of theMessage to true | |
end repeat | |
end using terms from | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
set saveDirectory to choose folder
This will pop the choosing folder dialog so you won't have to run script from terminal.
P.S.: Thanks for the script!