复制文本的.rtf与AppleScript的电子邮件的正文 [英] Copying .rtf text into the body of an email with AppleScript

查看:687
本文介绍了复制文本的.rtf与AppleScript的电子邮件的正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个创建一个电子邮件(Mail.app)与我在对话框中选择的选项附件的AppleScript应用程序。文本模板存储在的.rtf 格式,使非编程人员可以改变文本模板自己的意愿。

I have an AppleScript application which creates an email (in Mail.app) with attachments from the options I choose through dialogs. The text templates are stored in .rtf format so non-programers can alter the text templates to their wishes.

我能够创建从 .TXT 纯文本文件的电子邮件,但是当我导入的.rtf 文本文件,其进口的格式化命令,我不希望在邮件。

I am able to create an email from a .txt plain text file, but when I import an .rtf text file it imports the formatting commands, which I don’t want in the mail.

下面是一个的.rtf 导入到电子邮件的一个例子:

Here is an example of a .rtf import into an email:

{\\ RTF1 \\ ANSI \\ ansicpg1252 \\ cocoartf1038 \\ cocoasubrtf360
  {\\ fonttbl \\ F0 \\ fswiss \\ fcharset0黑体光强;}
  {\\ colortbl; \\ red255 \\ green255 \\ blue255;}
  \\pard\\tx560\\tx1120\\tx1680\\tx2240\\tx2800\\tx3360\\tx3920\\tx4480\\tx5040\\tx5600\\tx6160\\tx6720\\ql\\qnatural\\pardirnatural

{\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技术邮件讲英语\\

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

下面是我的脚本的一部分:

Here is part of my script:

-- 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 文件导入格式的文本到一个新的邮件不带格式codeS(我选择RTF,因为大多是大胆的和颜色是用来格式的文本)?

Is it possible to import formatted text from .rtf files into a new mail without the formatting codes (I choose rtf because mostly bold and color are used to format text)?

推荐答案

我觉得邮件发送电子邮件作为纯文本或HTML,RTF没有。所以,你需要发送的邮件为html不是RTF。注意:有一个技巧,通过使用的AppleScript邮件发送HTML电子邮件。出于某种原因,你可以将新的消息的Visible属性未设置​​为true。如果你这样做是行不通的。

I think Mail sends an email as either plain text or html, not rtf. So you would need to send your email as html not rtf. Note there's a trick to sending a html email with Mail via applescript. For some reason you can't set the visible property of the new message to true. It won't work if you do.

下面是如何这可以帮助你。您可以使用命令行工具textutil到RTF格式的HTML,然后将其作为电子邮件转换。请注意我用的整洁的命令,以确保HTML code是干净的。

Here's how this can help you. You can use the command line tool textutil to convert the rtf to html and then send it as an email. Notice I use "tidy" in the command to make sure the html code is clean.

因此​​,所有你需要做的就是把收件人的电子邮件地址和主题在这个脚本并运行它...

So all you need to do is put the receiver's email address and a subject in this script and run it...

set emailAddress to "someone@somewhere.com"
set theSubject to "My converted rtf to html"

set rtfFile to choose file with prompt "Choose the RTF file to email as HTML:" without invisibles
set theHTML to do shell script "/usr/bin/textutil " & " -stdout -format rtf -convert html " & quoted form of POSIX path of rtfFile & " | /usr/bin/tidy -b -utf8"

tell application "Mail"
    set newMessage to make new outgoing message at end of outgoing messages with properties {visible:false}
    tell newMessage
        make new to recipient at end of to recipients with properties {address:emailAddress}
        set subject to theSubject
        set html content to theHTML
        send
    end tell
end tell

这篇关于复制文本的.rtf与AppleScript的电子邮件的正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆