如何使用 Applescript 关闭打开的电子邮件

How to Close an open email using Applescript

我已经能够在 Mac OS X 10.10.1 上使用以下脚本获得 95% 的成功,但是,我无法收到我打开的电子邮件"Close"。有什么建议吗???

这是 Applescript:

using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
    tell application "Mail"

        -- walk through all matching messages
        repeat with thisMessage in theMessages
            -- open the message
            set openedMail to open thisMessage

            -- perform your UI scripting
            tell application "System Events"
                tell process "Mail"
                    -- Select the Print menu item
                    click (first menu item of menu "File" of menu bar 1 whose name begins with "Print")
                    tell window 1
                        -- Wait until the print sheet appears
                        repeat 30 times
                            if sheet 1 exists then exit repeat
                            delay 0.5
                        end repeat
                        tell sheet 1
                            -- Click the PDF button
                            click menu button "PDF"
                            -- Select the PDF to SBS Dropbox menu item
                            delay 0.5
                            click (first menu item of menu 1 of menu button "PDF" whose name begins with "PDF to SBS Dropbox")
                            delay 4
                        end tell
                    end tell
                end tell
            end tell

            -- close the message
            close openedMail

        end repeat
    end tell
end perform mail action with messages

停止使用来自

的条款

如果您的代码不起作用,那么为什么不尝试使用您之前在系统事件中使用的相同技术...

click (first menu item of menu "File" of menu bar 1 whose name begins with "Close")

或者您可以告诉邮件使用...

close window 1