【问题标题】:applescript for Mail.app to duplicate outgoing message and send as a newly formatted message用于 Mail.app 复制传出消息并作为新格式化消息发送的 applescript
【发布时间】:2011-11-10 04:28:44
【问题描述】:

所以我一直在寻找一种方法来执行以下操作,在 Mail.app 中按顺序使用 AppleScript:

  1. 拦截传出消息(我们称之为“A”)
  2. 制作和精确复制外发消息“A”的消息(我们称之为“B”)
  3. 格式化这条新消息(“B”)的文本/内容等
  4. 发送这条新格式化的消息(“B”)
  5. 忽略原来的(“A”)。

我为什么要做一些看起来如此迟钝的事情?

  • Apple 的 Mail.app amazingly doesn't format the outgoing content of your messages.
  • 通过执行基本的消息 > 首选项 > 等等,它只会改变 通过 Mail.app 看到的消息的字体样式。当您的收件人收到邮件时,选择的字体是客户端的默认字体(对于 Outlook 等客户端来说,这可能是令人讨厌的 Times New Roman)。

那么,为什么不直接要求一个 Applescript 来格式化您的外发消息呢?

仍在学习 AppleScript 的基本原理,因此如果有人能编写出符合要求的 AppleScript 将不胜感激。

我的意图是在我点击“发送消息”时触发 Applescript(通过可爱的键盘大师)。

这是我能想出的骨架 applescript 代码:

set theFont to "Lucida Sans, Lucida Sans Unicode, Lucida Grande, Verdana, Arial"
set theSize to 12
tell application "Mail"
    -- 1. intercept an outgoing message
    set outMsg to front outgoing message


    -- 2. make and exact duplicate of this outgoing message
    -- need a little help with extracting...
            set fmtMsg to make new outgoing message with properties 
        {   sender:,
            subject:”Convert”, 
            content:”Please convert and send”
            message signature:,
            to recipient:,
            cc recipient:,
            bcc recipient:
        }


    tell fmtMsg
                    -- 3. format the text/content etc of this newly made message
        set font of content to theFont
        set size of content to (theSize)
        -- set visible to true

                    -- 4. send this newly formatted message
        send

                    -- 5. disregard the original one.
                    -- help?
    end tell


end tell

干杯。

【问题讨论】:

标签: fonts applescript apple-mail


【解决方案1】:

我使用 Mail 的工作不多,但我编写了一个脚本来完成这项工作......

set the mail_recipient to the text returned of (display dialog "To:" default answer "")
set the mail_subject to the text returned of (display dialog "Subject:" default answer "")
set the mail_content to the text returned of (display dialog "Enter your message here (for a new line type \"\\n\"):" default answer "")
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to "\\" & "n"
set this_text to every text item of the mail_content
set AppleScript's text item delimiters to return
set the mail_content to this_text as string
tell application "Mail"
    tell (make new outgoing message with properties {visible:true, subject:mail_subject, content:mail_content})
        make new to recipient at the end of to recipients with properties {address:mail_recipient}
        send
    end tell
end tell

我没有在脚本中添加错误检查(检查收件人的有效地址)。

如您所说,您无法更改收件人的字体;这可能被视为骚扰。

如果此脚本不满意,请告诉我,我会为您更改。 :)

更新:我刚刚阅读了将 AppleScript 与 Mail 结合使用的内容,并且刚刚意识到 Mail 在 AppleScript 方面存在巨大限制。我认为你最好的选择是使用GUI Scripting。这个脚本有点老套,但它应该可以工作。

tell application "System Events" to tell process "Mail" to set the mail_subject to (get the value of the first text box)
tell application "Mail" to set this_message to the content of the first message of mailbox "Sent" whose subject is the mail_subject

更新 2:

tell application "System Events"
    tell process "Mail"
        set the mail_recipient to (get the value of the first text field)
        set the mail_subject to (get the value of the fourth text field)
        set the mail_content to (get the value of the last text field)
        my create_new_message(mail_recipient, mail_subject, mail_content)
    end tell
end tell

on create_new_message(recipient, subject, content)
    tell application "Mail"
         quit saving no
         activate
         tell (make new outgoing message with properties {subject:|subject|, content:|content|)
             make new recipient at the end of to recipients with properties {address:|recipient|}
             send
         end tell
    end tell
end create_new_message

【讨论】:

  • 嘿,谢谢!虽然绝对有用,但我认为它不能满足我的确切要求。我想“从现有的传出消息”创建一个邮件消息。基本上,我已经编写了我的消息,添加收件人,主题等。点击发送后,我希望Applescript重新创建整个消息>设置格式然后发送。我认为你的脚本会提示收件人,主题等。我希望脚本选择这是从已经填满的现有发送消息窗口中提取的。(另一个优点:即使我正在回复/转发我的消息,重新创建过程也会把它全部捡起来)。
  • 是的,我认为我可能不得不求助于某种 GUI 脚本,正如我帖子中的第二个链接所建议的那样。不过,您改变了解决方案:从“已发送”框中选择一封邮件,这意味着我已经发送了邮件?我希望能够创建一条与“将要发送”的消息具有相同属性的新消息,在新消息上设置格式(我可以使用我的 qn 中的 AppleScript 执行此操作),“丢弃”“将被发送”一个,并且只发送新的。所以基本上我应该只收到一条发送的消息。那有意义吗? (更新了我的问题以使其更清楚)
  • 是的,我认为这应该完全满足我想要的。虽然在脚本上出现了一些编译错误,Expected "," but found identifier 在该行:将 mail_recipients 设置为(获取第一个文本 box 的值)跨度>
  • @Kaushik Gopal 哎呀!这是我的错;我忘了它是text field 而不是text box。对不起!
猜你喜欢
  • 2018-06-26
  • 2016-01-20
  • 2015-09-02
  • 1970-01-01
  • 2017-02-13
  • 1970-01-01
  • 1970-01-01
  • 2018-05-12
  • 2011-10-02
相关资源
最近更新 更多