首页 > 解决方案 > 为什么我在 AppleScript 命令中的击键不能将打开的电子邮件信息变成“外发”信息?

问题描述

我正在尝试实现一个 AppleScript 来查找邮箱中保存的外发电子邮件草稿的电子邮件。然后应该打开在那里找到的每一个, ,变成一个传出消息,然后发送。我已经非常接近了,但是在下面的脚本中,击键命令什么都不做。它应该通过调用“再次发送”将消息转换为传出消息。

using terms from application "Mail"
    tell application "Mail"
        set theMailbox to mailbox "OutgoingEmail" of account "iCloud"
        set foundMsgs to (every message in theMailbox)
        set the messageCount to the count of foundMsgs
        repeat with i from 1 to the messageCount
            set newMsg to item i of foundMsgs
            tell newMsg
                open
                tell application "System Events"
                    tell application process "Mail"
                        keystroke "D" using {shift down, command down}
                    end tell
                end tell
            end tell
        end repeat
    end tell
end using terms from

但它什么也没做。消息已打开,但击键无效。下一步是发送消息,但脚本中没有显示。

标签: macosemailapplescript

解决方案


我认为您不需要使用“使用邮件中的条款”命令,因为您在下一行有一个邮件通知块。

试试这段代码,看看它是否有效。

    tell application "Mail"
        set theMailbox to mailbox "OutgoingEmail" of account "iCloud"
        set foundMsgs to (every message in theMailbox)
        set the messageCount to the count of foundMsgs
        repeat with i from 1 to the messageCount
            set newMsg to item i of foundMsgs
            tell newMsg
                open

            end tell
tell application "System Events"
                    tell application process "Mail"
                        keystroke "D" using {shift down, command down}
                    end tell
                end tell
        end repeat
    end tell

还可以尝试仅包含系统事件命令的单独脚本,以查看它们是否单独工作...

tell application "System Events"
                    tell application process "Mail"
                        keystroke "D" using {shift down, command down}
                    end tell
                end tell

推荐阅读