using terms from application "Mail" on perform mail action with messages selectedMessages for rule theRule set parentFolder to (path to desktop folder) as string set folderName to "TEST" my makeNewAttachmentsFolder(parentFolder, folderName) set attachmentsFolder to parentFolder & folderName & ":" tell application "Mail" try ignoring case repeat with theMessage in selectedMessages repeat with theAttachment in (theMessage's mail attachments whose (its name ends with ".pdf")) set originalName to name of theAttachment my makeNewEmptyFile(attachmentsFolder, originalName) save theAttachment in file (attachmentsFolder & originalName) end repeat end repeat end ignoring end try end tell end perform mail action with messages end using terms from on makeNewAttachmentsFolder(parentFolder, folderName) try tell application "Finder" to make new folder at folder parentFolder with properties {name:folderName} end try end makeNewAttachmentsFolder on makeNewEmptyFile(attachmentsFolder, newFileName) try tell application "Finder" to make new file at folder attachmentsFolder with properties {name:newFileName} end try end makeNewEmptyFile