Skip to content

Instantly share code, notes, and snippets.

@aharpole
Created December 10, 2025 21:33
Show Gist options
  • Select an option

  • Save aharpole/8f8e14f0805bba4e4ff5c567091bf3c8 to your computer and use it in GitHub Desktop.

Select an option

Save aharpole/8f8e14f0805bba4e4ff5c567091bf3c8 to your computer and use it in GitHub Desktop.
Apple Mail save all attachments
-- Save all attachments from selected messages/threads in Mail
-- to the current user's Downloads folder.
tell application "Mail"
-- Get current selection
set theSelection to selection
if theSelection is {} then
display alert "No messages selected." message "Select one or more messages or threads in Mail, then run this script again."
return
end if
-- Resolve the Downloads folder as an HFS path (AppleScript-style text)
set downloadsFolder to (path to downloads folder) as rich text
repeat with selectedItem in theSelection
set itemClass to class of selectedItem
set messageList to {}
if itemClass is message then
-- A normal message
set messageList to {selectedItem}
else if itemClass is thread then
-- A conversation / thread; grab all its messages
set messageList to (messages of selectedItem)
else
-- Ignore anything that isn't a message or thread
end if
-- Process each message in the current item
repeat with aMessage in messageList
set theAttachments to every mail attachment of aMessage
repeat with anAttachment in theAttachments
set attachmentName to name of anAttachment
set savePath to downloadsFolder & attachmentName
try
save anAttachment in file savePath
on error errMsg number errNum
-- Optional: comment out this line if you don't care about individual failures
log "Failed to save attachment \"" & attachmentName & "\": " & errMsg
end try
end repeat
end repeat
end repeat
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment