Created
August 30, 2012 20:14
-
-
Save martintajur/3539777 to your computer and use it in GitHub Desktop.
Convert selected emails from Apple Mail app to files on Desktop
This file contains 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
# taken from http://macscripter.net/viewtopic.php?id=17655 | |
# be sure to replace [username] with your username folder! | |
using terms from application "Mail" | |
on perform mail action with messages theMessages | |
tell application "Finder" to set ptd to (path to desktop folder) as string | |
tell application "Finder" to set pathToAttachments to "iMac:Users:[username]:Desktop:" & "Attachments:" | |
tell application "Mail" | |
repeat with theMessage in theMessages | |
set theText to (all headers of theMessage & content of theMessage) | |
if theMessage's mail attachments is not {} then | |
repeat with theAttachment in theMessage's mail attachments | |
set theFileName to pathToAttachments & (theMessage's id as string) & space & theAttachment's name | |
try | |
save theAttachment in theFileName | |
on error errnum | |
end try | |
end repeat | |
end if | |
set theFile to ptd & "Message Number " & (theMessage's id as string) | |
set theFileID to open for access file theFile with write permission | |
write theText to theFileID | |
close access theFileID | |
end repeat | |
end tell | |
end perform mail action with messages | |
end using terms from | |
tell application "Mail" | |
set myMessages to selection | |
tell me to perform mail action with messages myMessages | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment