我是Applescript的新手......
在 Apple Mail 中,您可以将电子邮件另存为文本文件:文件 > 另存为... > 格式化“纯文本”
非常感谢。
Mail.app 不会以编程方式将所选邮件导出到 TXT。您可以使用 GUI 脚本,但在这种情况下,GUI 脚本是不好的解决方案。以其他方式存在,此处描述。
该脚本假定邮件在 Mail.app 中被选中,并在桌面上创建文本文件,但您可以指定其他文件夹。.
-- Mail.app: Export Selected Message to plain text (.txt) file
-- written: by me, right now
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
set timeZone to (abbreviation of (current application's NSTimeZone's localTimeZone())) as text
-- Mail.app part (load remote content, get message properties)
tell application "Mail"
set download html attachments to true -- load remote content as well
tell (item 1 of (get selection)) -- here we tell to 1st selected message
set {theSubject, fromHider} to {subject, "From: " & sender}
tell (get date sent) -- build here "Date: ....." text line
set dateSentHider to "Date: " & date string & " - " & time string & " " & timeZone
end tell
set {toHider, messageContent} to {"To: " & address of to recipient 1, content}
end tell
end tell
set allText to fromHider & linefeed & "Subject: " & theSubject & linefeed & dateSentHider & ¬
linefeed & toHider & linefeed & linefeed & messageContent
-- replace every ":" symbol in theSubject with "_"
set {ATID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
set {itemList, AppleScript's text item delimiters} to {text items of theSubject, "_"}
set {theSubject, AppleScript's text item delimiters} to {itemList as text, ATID}
-- build destination file's Posix path, write to it
set theFile to POSIX path of (path to desktop folder) & theSubject & ".txt"
-- or,
-- set theFile to POSIX path of (choose folder) & theSubject & ".txt"
(current application's NSString's stringWithString:allText)'s writeToFile:theFile atomically:true ¬
encoding:(current application's NSUTF8StringEncoding) |error|:(missing value)
您也可以在剪贴板中保存消息(以 txt“格式”)。简单地:
set the clipboard to allText
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句