我有一个 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/