如何使用applescript将电子邮件另存为txt文件

我是Applescript的新手......

在 Apple Mail 中,您可以将电子邮件另存为文本文件:文件 > 另存为... > 格式化“纯文本”

  1. 是否可以使用 applescript 自动化?
  2. 是否可以使用applescript将邮件(以txt“格式”)保存在剪贴板中,而不是保存为txt文件?

非常感谢。

罗伯特·克尼亚齐迪斯

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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

电子邮件备份/存档程序,将电子邮件另存为* .txt文件

使用Powershell将电子邮件另存为.MSG到本地文件夹

使用MailKit c#时,是否可以将电子邮件另存为文件?

如何使用 Excel VBA 将另存为 HTML 电子邮件?

将Outlook电子邮件另存为PDF +附件

将电子邮件另存为 PDF

将Outlook电子邮件另存为.msg文件到我的内部驱动器

通过 MS Access VBA 将选定的 Outlook 电子邮件另存为 .msg 文件

使用Windows Service将电子邮件另存为.eml

哪种电子邮件格式可将电子邮件另存为单个文件,平台无关且可搜索?

将Outlook 2010中的附件电子邮件联系人另存为通讯组

如何使用AppleScript在Firefox的“另存为”对话框中输入文件名?

VBA:Word将.docx文件另存为.doc文件,如何另存为docx?

VBA Excel将副本另存为txt文件

Matlab:将工作区变量另存为.txt文件

将Python结果另存为.txt文件

AS3将列表另存为.txt文件

将numpy数组另存为txt文件[入门]

如何将Excel电子表格另存为以分号分隔的值文件?

如何将列表框另存为 txt

如何通过可下载的链接将文本另存为.txt文件?

将 Excel 文件另存为 txt 时如何防止重复额外的倒转逗号

如何将Swift中的Float数组另存为txt文件

如何将图像PDF文件另存为图像?

如何将html文件另存为pdf?

DocuSign如何将私钥另存为.PEM文件

如何将Quanteda词典另存为yaml文件?

如何使用NPOI c#将xls文件另存为xlsx文件?

使用for循环将数据帧另存为.Rdata文件