【问题标题】:Using AppleScript to set a mail message to Plain Text使用 AppleScript 将邮件消息设置为纯文本
【发布时间】:2012-08-23 03:30:07
【问题描述】:

我有一个 AppleScript,它可以很好地整理信息并创建带有附件的电子邮件。

我找不到脚本将消息格式设置为接收收件箱所需的“纯文本”(而不是默认的“富文本”)的方法。

是否有 AppleScript 方法(或技巧)将消息格式设置为“纯文本”?

【问题讨论】:

    标签: applescript plaintext apple-mail


    【解决方案1】:

    在脚本中创建消息的部分之前,添加此行。

     tell application "Mail" to set default message format to plain text
    

    在脚本的最后添加这个来重置值

     tell application "Mail" to set default message format to rich text
    

    【讨论】:

    • 不幸的是,这给了我一个 AppleScript 错误Mail got an error: Can’t make string into type constant.
    • 你试过自己运行命令吗?它适用于 10.6.8 和 Mail 4.5。
    • 我在 10.8.1 上运行 Mail 版本 6.0。根据您的线索查看 AppleScript 字典后,我发现格式似乎从 set default message format to plain text 更改为 set default message format to plain format 这将编译并运行 - 但不幸的是,该消息仍在富文本中。
    • 所以你可以运行纯文本脚本,然后创建一个新消息,在正文中输入几个单词,突出显示它们并点击命令 B 使其变为粗体?
    • 是的,即使我设置为纯文本然后创建它仍然以富文本格式发送的消息。这不是我对邮件消息的任何“编辑”。如果我检查 AppleScript 发送的邮件的邮件头,它们将包含Content-Type: TEXT/HTML;。如果我手动发送带有从 Mail.app 中选择的纯文本的消息,标题将仅包含 Content-Type: text/plain;
    【解决方案2】:

    我在尝试解决这个问题时发现了这个问题。最终我想出了以下解决方案:

    tell application "Mail"
        set newMessage to make new outgoing message 
            with properties {visible:true,
                             subject:"message title",
                             sender:"sender@from.address",
                             content:mailBody}
        tell newMessage
            make new to recipient with properties {address:"mail@recipient.com"}
        end tell
        activate
    end tell
    
    tell application "System Events"
        click menu item "Make Plain Text" of ((process "Mail")'s (menu bar 1)'s (menu bar item "Format")'s (menu 1))
    end tell
    

    希望有人会觉得这很有用,我知道我会在几个小时前找到!

    这是在 Mail 版本 7.3 和 12.4 上测试的。新旧版本可能需要不同的菜单标题。

    【讨论】:

      【解决方案3】:

      您也可以使用键盘快捷键 shiftt 将消息格式更改为 plain text

      tell application "System Events" to keystroke "t" using {command down, shift down}
      

      在邮件版本 12.4 中测试

      【讨论】:

        猜你喜欢
        • 2017-01-27
        • 2017-02-13
        • 2015-06-25
        • 1970-01-01
        • 2011-09-09
        • 2021-10-02
        • 1970-01-01
        • 2015-12-05
        相关资源
        最近更新 更多