Applescript Selecting Specific Inbox in Apple Mail

4.5k views Asked by At

I am new to Applescript and I am running into an issue. I have multiple folder in my Mail "Inbox". However, I would like to just select one of these inboxes to run the script on it.

Here is what I have. However, I cannot seem to find the Inbox for the Gmail account.

Any ideas?

    set _ago to (current date) - days
    set _inbox to "Inbox:Gmail"

    tell application "Mail"
        move (messages of _inbox whose read status is false and date received comes before _ago) to mailbox "Gmail - Unread"
        move (messages of _inbox whose date received comes before _ago) to mailbox "Gmail - Archive"
    end tell
1

There are 1 answers

1
Antal Spector-Zabusky On

It seems, although I haven't seen this documented anywhere, that inboxes are always mailboxes named "INBOX" (case matters). Thus, the following is what I do when I need to access an account-specific inbox:

set _inbox to mailbox "INBOX" of account "Gmail"

It's the same way you'd access any mailbox, you just use this particular name. Note also that you might need to use the mailbox "Unread" of account "Gmail" form in your move statements as well, but I'm not sure; you'd need to test this.