using terms from application "Mail" on perform mail action with messages theMessages set attachmentsFolder to "Macintosh HD:Library:pgAgent:MyPictures:" as rich text tell application "Mail" set selectedMessages to theMessages try repeat with theMessage in selectedMessages repeat with theAttachment in theMessage's mail attachments if the MIME type of theAttachment begins with "image" then set originalName to name of theAttachment set savePath to attachmentsFolder & originalName save theAttachment in file savePath end if end repeat end repeat end try end tell end perform mail action with messages end using terms from