AppleScript: Duplicating (copying) all messages to other acct

I’m trying to create an AppleScript for Yosemite that makes copies (not archives) of messages.

Let’s say I have 3 accounts:

Master (IMAP)
Target 1 (IMAP)
Target 2 (Exchange)

I want to select all the messages in the Master inbox – and copy (aka duplicate) those messages to the inboxes of two other accounts, Target 1 and Target 2. In the end, there will be three inboxes, all with the same set of messages – again copies (not archives).

I’ve tried things like:

set mailboxMaster to "Master" set mailboxTargets to {"Target 1", "Target 2"}

repeat with curMailboxTarget in mailboxTargets tell application "Mail" duplicate every message in mailbox "Master" to mailbox curMailboxTarget end tell end repeat

but I get “Mail got an error: Can’t set mailbox”

Ideas? Thanks!


I have 3 accounts in Mail. I ran this simple script with one inbox message selected:

tell application "Mail"
end tell

This was the reply:

{message id 7059 of mailbox "INBOX" of account "acount_name" of application "Mail"}

As you can see, mailboxes belong to an account.
Furthermore, the answer uses of, not in, to describe the location.

Please use the Applescript button when posting scripts.

You do know that Mail can do this for itself (without an AppleScript) as the messages arrive, right?


The problem is that “Mail” and “reliable” can never occur in the same sentence. :slight_smile:

At this point, it doesn’t matter much. I’ve been able to work around it.