Cheesenightmare
Cheesenightmare

Reputation: 21

How can i modify this applescript to apply to selected emails rather than selected mailboxes?

tho is my first post - glad to have found this community :)

I'm afraid I have limited applescript knowledge but I discovered a script that will create a new message with recipients based on senders of emails in a particular mailbox.

This is almost what I need...

What I really need is a script that will create a new message with recipients based on senders of all selected emails.

I am actually astonished that this is not an option in more mail clients. It's not an option in Mail, nor Mailmate, nor Entourage.

The code I am working with is...

tell application "Mail"
    set theSenderList to {}
    set theMailboxes to the selected mailboxes of message viewer 0
    repeat with aMailbox in theMailboxes
        repeat with aMessage in messages of aMailbox
            set end of theSenderList to sender of aMessage
        end repeat
    end repeat
    set newMessage to make new outgoing message with properties {visible:true, subject:"Answers to ", content:"Here is the solution to "}
    repeat with aSender in theSenderList
        tell newMessage
            make new bcc recipient at end of bcc recipients with properties {address:aSender}
        end tell
    end repeat
end tell

Upvotes: 2

Views: 1711

Answers (1)

outis
outis

Reputation: 77400

To access the selected messages, you can simply use selected messages instead of selected mailboxes. Once you've made this change, the loop over the selected mailboxes no longer applies. Instead, keep just the inner loop over messages.

    ...
    set theMessages to the selected messages of message viewer 0
    repeat with aMessage in theMessages
        set end of theSenderList to sender of aMessage
    end repeat
    ...

To find this sort of thing yourself:

  1. open the AppleScript editor,
  2. open the library window (Window → Library, or ⇧⌘L)
  3. add the application to the library (click the plus symbol in the library window),
  4. open the scripting dictionary for the application (double click the application in the library window)
  5. Select the Mail suite, then the message viewer class in the browser.

You can also open a scripting dictionary via File → Open Dictionary..., or with ⇧⌘O.

In the properties for the message viewer, you'll see both "selected messages" and "selected mailbox".

The dictionary viewer uses a number of icons in the browser to indicate the type for a term

  • Suite: an "S" in an orange square.
  • Class: a "C" in a purple square.
  • Command: a "C" in a blue circle.
  • Element: an "E" in an orange square.
  • Property: a "P" in a purple square.

See Also

Upvotes: 2

Related Questions