使用javascript(JXA)代替applescript

时间:2018-03-03 19:27:45

标签: macos applescript jxa

我正在尝试在JXA中创建一个电子邮件解析器。我能够在applescript中做类似的事情:

tell application "Mail" to set theMessages to every message of mailbox "Inbox" of account "MyAcount" whose subject is equal to "Search Text"

repeat with aMessage in theMessages
    tell application "Mail" to set {mContent, mDate} to {content, date received} of aMessage
    ......process each mail.....
end repeat

我如何在javascript中复制此内容?

1 个答案:

答案 0 :(得分:0)

也许有这样的事情。希望这会有所帮助。

(() => {
    'use strict';

    const
        appMail = Application('Mail'),
        account = appMail.accounts.byName('MyAccount'),
        inbox = account.mailboxes.byName('INBOX'),
        listMessages = inbox.messages.whose({
            subject: 'Search Text'
        })();

    return listMessages.map(x => {
            const [mContent, mDateReceived] = [x.content(), x.dateReceived()];
            ...
        }

    )
})();