Created
March 21, 2023 01:35
-
-
Save stevenrick/99dd7035efe82b7e9ea1871b11a09624 to your computer and use it in GitHub Desktop.
Apple Script to extract Mail messages to txt files
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
using terms from application "Mail" | |
--save selected messages to text files | |
on perform mail action with messages messageList | |
set theFolder to choose folder with prompt "Save Exported Messages to..." without invisibles | |
set the message_count to the count of messageList | |
display dialog "Found " & (message_count) & " messages." | |
repeat with i from 1 to the message_count | |
set this_message to item i of messageList | |
set theFile to (((theFolder) as Unicode text) & (i) as Unicode text) & ".txt" | |
set theContent to (content of this_message) as Unicode text | |
try | |
set theFileID to open for access theFile with write permission | |
write theContent to theFileID | |
close theFileID | |
on error | |
display dialog "Can't write message" | |
end try | |
end repeat | |
display dialog "Done exporting " & (message_count) & " messages." | |
end perform mail action with messages | |
end using terms from | |
using terms from application "Mail" | |
on run | |
tell application "Mail" to set mySelection to selection | |
tell me to perform mail action with messages (mySelection) | |
end run | |
end using terms from |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment