Skip to content

Instantly share code, notes, and snippets.

@nst
Created September 21, 2012 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nst/3761057 to your computer and use it in GitHub Desktop.
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.
-- 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
@hryamzik
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment