Mail.app 的 applescript 可以复制外发邮件并作为新格式的邮件发送

发布于 2024-12-03 07:06:55 字数 2040 浏览 1 评论 0原文

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

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

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

  • Apple 的 Mail.app 令人惊讶的是不会格式化您的邮件的传出内容。< /a>
  • 通过执行基本消息>偏好>等等,它仅更改通过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

干杯。

So i've been searching around for a way to do the following, sequentially in Mail.app, using AppleScript:

  1. intercept an outgoing message (let's call this "A")
  2. make and exact duplicate message (let's call this "B") of the outgoing message "A"
  3. format the text/content etc of this newly made message ("B")
  4. send this newly formatted message ("B")
  5. disregard the original one ("A").

Why would i want to do something that appears to be so retarded?

  • Apple's Mail.app amazingly doesn't format the outgoing content of your messages.
  • By doing the basic Message > Preference > etc etc it only changes the font-style of the message that you see through Mail.app. When your recipient gets the message, the font chosen is that of the client's default (which can be an abhorring Times New Roman for clients like Outlook).

So why not just ask for an Applescript that formats your outgoing message directly?

Still learning the ropes with Applescript, so would greatly appreciate it if anyone could cook up an AppleScript that does the requested.

My intention is to trigger the Applescript when i hit "Send Message" (through the lovely Keyboard Maestro).

Here's the skeleton applescript code i could come up with:

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

Cheers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还给你自由 2024-12-10 07:06:55

我没有太多使用邮件,但我编写了一个应该完成这项工作的脚本...

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

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

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

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

更新: 我刚刚阅读了有关在 Mail 中使用 AppleScript 的内容,并且刚刚意识到 Mail 对于 AppleScript 有巨大的限制。我认为最好的选择是使用 GUI 脚本。这个脚本有点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

I haven't worked with Mail that much, but I've composed a script that should do the job...

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

I haven't added error checking in the script (check for a valid address for the recipient).

As you said, you can't change the recipient's font; that might be considered harassment.

If this script isn't satisfactory, just let me know and I'll change it for you. :)

UPDATE: I just read up on using AppleScript with Mail, and just realized that Mail has huge limitations regarding AppleScript. I think your best bet would be to use GUI Scripting. This script is kind of hacky, but it should work.

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

UPDATE 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文