I’ve created a script for Mail that when run opens a dialog box with a list of sender addresses. I click on one of the items in the list and Mail.app generates a new message with the selected sender address. This will help me manage my different account aliases.
This is what I currently see in the list that pops up:
When I select one of these, say, Friends, the script hunts down the correct information to put in the Mail.app account section (Justy friends@domain.com).
tell application "Mail"
set theResult to choose from list {"Justy <friends@domain.com>", "Justy <family@domain.com>"} with prompt ¬
"Select sending account:" default items {"Justy <friends@domain.com>"} with multiple selections allowed and empty selection allowed
set fromAddress to item 1 of theResult
make new outgoing message with properties {visible:true, sender:fromAddress}
end tell
tell application "Mail"
set List1 to {"Justy <me@domain.com>", "Justy <friends@domain.com>", "Justy <family@domain.com>"}
set List2 to {"Me", "Friends", "Family"}
set fromAddress to {}
set TargetItem to choose from list List2 with multiple selections allowed and empty selection allowed
repeat with p from 1 to count of TargetItem
repeat with i from 1 to count of List2
if item i of List2 is item p of TargetItem then copy item i of List1 to end of fromAddress
end repeat
end repeat
make new outgoing message with properties {visible:true, sender:fromAddress}
end tell
return fromAddress
Well, I have never scripted mail so I was kind of guessing what you wanted. What I have done is created a list of senders which could have multiple senders since you enabled multiple selections. So the variable fromAddress is a list. If you want to have multiple senders then you need a loop to pass the individual strings that have the addresses to mail to create multiple e-mails. If you just want one sender then you could alter the filter to set a string for the sender rather than a list and not allow multiple selections.
I wish I could write these things from scratch myself but it takes me weeks. Taken most of the day just to get that first one done, and that was adapted from someone else’s script.
The thing that seemed to make the account change work in that first script was the addition of “set fromAddress to item 1 of theResult”. I’ve had a quick dabble with your script but can’t get it to work. I really have no idea what I’m doing.
Can you give me another example that might do the trick?
I think, it’s not necessary to work with mulitple selection allowed.
This is a bit simpler:
tell application "Mail"
set List1 to {"Justy <me@domain.com>", "Justy <friends@domain.com>", "Justy <family@domain.com>"}
set List2 to {"Me", "Friends", "Family"}
set TargetItem to item 1 of (choose from list List2 with prompt "Select account")
if TargetItem is false then return
repeat with p from 1 to count of List1
if TargetItem is item p of List2 then
copy item p of List1 to fromAddress
exit repeat
end if
end repeat
make new outgoing message with properties {visible:true, sender:fromAddress}
end tell