applescript - 使用 AppleScript 将 .rtf 文本复制到电子邮件正文中

标签 applescript rtf

我有一个 AppleScript 应用程序,它可以创建一封电子邮件(在 Mail.app 中),其中包含我通过对话框选择的选项中的附件。文本模板以 .rtf 格式存储,因此非程序员可以根据自己的意愿更改文本模板。

我可以从 .txt 纯文本文件创建电子邮件,但是当我导入 .rtf 文本文件时,它会导入格式化命令,而我不这样做不想在邮件中。

以下是将 .rtf 导入电子邮件的示例:

{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf360 {\fonttbl\f0\fswiss\fcharset0 Helvetica-Light;} {\colortbl;\red255\green255\blue255;} \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural

\f0\fs24 \cf0 technology mail for english speakers\

这是我的脚本的一部分:

-- Import the .rtf file and store content in the mycontent variable    
set mycontent to (read "/Users/kiara/Desktop/mailer/technology/tech-en-content.rtf")
…
…
-- create mail from values stored in variables
tell application "Mail"
    set theMessage to make new outgoing message with properties {visible:true, subject:mysubject, content:mycontent}
    tell content of theMessage
        make new attachment with properties {file name:this_file} at after last paragraph
    end tell
end tell

是否可以将格式化文本从 .rtf 文件导入到新邮件中,而无需格式化代码(我选择 rtf,因为大多数情况下使用粗体和颜色来格式化文本)?

最佳答案

这是另一种方法:

set the clipboard to (read "/Users/kiara/Desktop/mailer/technology/tech-en-content.rtf" as «class RTF »)

tell application "Mail"
    activate
    set theMessage to make new outgoing message with properties {visible:true, subject:"mysubject"}
end tell

tell application "System Events"
    tell process "Mail"
        repeat until focused of UI element 1 of scroll area 4 of window 1
            keystroke tab
        end repeat
        keystroke "v" using command down
    end tell
end tell

关于applescript - 使用 AppleScript 将 .rtf 文本复制到电子邮件正文中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10658483/

相关文章:

c++ - 通过正则表达式崩溃删除 RTF 标签

vba - 在 Excel 中将 RTF(富文本格式)代码转换为纯文本

java - 在 Lucene 中索引 RTF 文件且字段完好无损

excel - 尝试使用 AppleScript 将 .xls 和 .xlsx 转换为 .txt(制表符分隔),需要修复

unix - 使用 applescript 显示 Unix Exctable 文件

applescript - AppleScript 中的用户属性/权限

iphone - 如何从 iPhone 应用程序中的 URL 读取 .rtf 文件

delphi - 如何在 Delphi 中显示格式化(颜色、样式等)日志?

compiler-errors - 脚本新手: error "Finder got an error: Can’ t get folder

javascript - JXA 将消息移动到不同的文件夹/邮箱