使用 AppleScript 将 .rtf 文本复制到电子邮件正文中 [英] Copying .rtf text into the body of an email with AppleScript

查看:24
本文介绍了使用 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 英文技术邮件\

这是我的脚本的一部分:

-- 导入 .rtf 文件并将内容存储在 mycontent 变量中将 mycontent 设置为(阅读/Users/kiara/Desktop/mailer/technology/tech-en-content.rtf")……-- 从变量中存储的值创建邮件告诉应用程序邮件"设置 theMessage 以使用属性 {visible:true, subject:mysubject, content:mycontent} 制作新的外发消息告诉消息的内容在最后一段之后创建具有属性 {file name:this_file} 的新附件结束告诉结束告诉

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

解决方案

这是另一种方法:

将剪贴板设置为(将/Users/kiara/Desktop/mailer/technology/tech-en-content.rtf"读作«class RTF »)告诉应用程序邮件"启用设置 theMessage 以创建具有属性 {visible:true, subject:"mysubject"} 的新外发消息结束告诉告诉应用程序系统事件"告诉进程邮件"重复直到聚焦窗口 1 的滚动区域 4 的 UI 元素 1击键选项卡结束重复使用向下命令击键v"结束告诉结束告诉

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.

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.

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

{\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\

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

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)?

解决方案

Here is another approach:

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 将 .rtf 文本复制到电子邮件正文中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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