mail.app的applescript复制传出消息并作为新格式化的消息发送

时间:2011-09-04 17:34:55

标签: fonts applescript apple-mail

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

  1. 拦截传出消息(让我们称之为“A”)
  2. 制作并完全重复的消息(让我们称之为“B”)传出消息“A”
  3. 格式化此新制作的消息(“B”)
  4. 的文本/内容等
  5. 发送此新格式化的消息(“B”)
  6. 忽略原来的(“A”)。
  7. 为什么我要做一些看似迟钝的事情?

    • 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
    

    干杯。

1 个答案:

答案 0 :(得分: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。这个脚本有点hacky,但它应该可以工作。

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
相关问题