1

I am a blind voiceover user of mac.

The new Mail.app makes it difficult to copy the sender's email. I would like to have a script which copies the sender email only, of one or more selected messages.

Is it possibile ?

2

Yes, AppleScript makes it easily possible !

Here is an AppleScript which can do that :

tell application "Mail"
    set theSenderList to {}
    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
    set the clipboard to (theSenderList as rich text)
    beep
end tell

It will cop the mail senders to the clipboard as following: John Doe <John.Doe@gmail.com>


The same script without the names :

tell application "Mail"
    set theSenderList to {}
    set theMessages to the selected messages of message viewer 0
    repeat with aMessage in theMessages
        set end of theSenderList to (extract address from sender of aMessage)
    end repeat
    set AppleScript's text item delimiters to " "
    set the clipboard to (theSenderList as string)
    set AppleScript's text item delimiters to ""
    beep
end tell

It outputs only the addresses with a space delimiter : john.doe@gmail.com jane.doe@gmail.com


For the beep, just add beep before the end tell (as I already did above).

0

Two possible modifications to the very useful code by Matthieu:
1. You could have it speak each address as it finds it (if that is useful) by using the say command.
2. Some consider it good form to preserve what AppleScript's text item delimiters were before changing them, then restore them back to original settings, instead of assuming that was a null character (""), especially if this might run while other scripts are running, since it is a global property.

tell application "Mail"
    set theSenderList to {}
    set theMessages to the selected messages of message viewer 0
    repeat with aMessage in theMessages
        set oneAddress to extract address from sender of aMessage
        set end of theSenderList to oneAddress
        say "found: " & oneAddress
    end repeat
    set {prevDelims, AppleScript's text item delimiters} to {AppleScript's text item delimiters, " "}
    set the clipboard to (theSenderList as string)
    set AppleScript's text item delimiters to prevDelims
end tell
0

An update to Matthieu's answer, to remove duplicates and add a new line between each address:

tell application "Mail"
    set theSenderList to {}
    set theMessages to the selected messages of message viewer 0
    repeat with aMessage in theMessages
        set theSender to sender of aMessage
        if theSender is not in theSenderList then
            set end of theSenderList to theSender
            set end of theSenderList to "
"
        end if
    end repeat

    set the clipboard to (theSenderList as rich text)
    beep
end tell

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .