2

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
Leo
  • 37,640
  • 8
  • 75
  • 100
  • Nice question title for a first question. You will probably want to point out in the question exactly what part of the code is not working for you. – Bert Nov 26 '11 at 22:53

1 Answers1

2

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

Community
  • 1
  • 1
outis
  • 75,655
  • 22
  • 151
  • 221
  • Thank you - the library is a great place for me to start. I don't think I can simply replace "selected mailboxes" with "selected messages" though... doing that returns an error and I am sure i would have to replace the other references to mailbox that are in that script such as "aMailbox" and "theMailbox" – Cheesenightmare Nov 26 '11 at 07:36
  • @Cheesenightmare: whenever you're learning a new application, play with the menu items. "Window" is particularly useful. As for editing the script, you no longer need the loop over the mailbox because it no longer deals with a mailbox. The "simply" refers to accessing the selected messages rather than the selected mailbox. – outis Nov 26 '11 at 07:39
  • Thanks @outis I will crack on trying to figure this out. Really appreciate your response. – Cheesenightmare Nov 26 '11 at 07:47
  • In all honest I am not trying to learn applescript..automator is about as deep as i get :) I'm just trying to customise a script to solve a very simple function...replying to several senders of different emails at once. Is there a service you could recommend where I could have this looked at? – Cheesenightmare Nov 26 '11 at 08:09
  • @Cheesenightmare: a forum might serve your needs better. Two big ones for Macs are at [discussions.apple.com](https://discussions.apple.com/index.jspa) and [forums.macrumors.com](http://forums.macrumors.com/); a web search would easily turn up these and others. However, you'll get further if you show you're willing to work on your own problems rather than just pawning them off on other people. AppleScript was designed to have an [english-like syntax](http://scripting.com/applescript/alanBaer.html) to be more approachable (though this effort fails for other reasons). – outis Nov 26 '11 at 08:36