Accessing an Object Inside a Tell Block

Hi gang -

First, I must again praise this forum. WOW, have I learned so much by cramming in all the materials you folks have contributed over the years. Truly, I have read several books on AppleScript over the years (all older, since rarely do new ones come out), and none of those books had the practical examples I’ve found in FAQs, posts, and Q&As here!

Now, I’ve run into a problem. I finally figured out that I could use “my” to access a handler from inside a Tell block, but now I have a situation where I am automating mail and I cannot figure out how to work around it.

I have a tell block started for the mail application ( tell application “Mail”) then I have another tell block that is a part of a repeat where I cycle through all unread messages (tell each_message).

What I need to do is move the current message into the archive of the that account. I thought the code (outside of a tell block) would look something like this:

set mailbox of each_message to mailbox "ARCHIVE" of account "booking@company.com"

… but that won’t work due to the context (it can’t access the mailbox).

What is the best way to deal with this?

Thanks in advance for the education -
Chris

If you want to move the message, just do it:

move each_message to mailbox "ARCHIVE" of account "booking@company.com"

The Mail.app shows on top of the left side of window mailboxes, whose owner is Mail.app itself. Because the Mail.app has mailboxes of 2 kind:

  1. mailboxes of Mail.app,
  2. mailboxes of every account

I guess the OP’s script doesn’t work because “ARCHIVE” is mailbox of Mail.app.

So, correct code should be like this:


move each_message to mailbox "ARCHIVE" of appication "Mail"