Hi there,
First off, and perhaps most importantly, all this is happening under 10.3.4.
I'm trying to write an AppleScript that I'll use as a PDF workflow option, to help automate the emailing of this newsletter my mom writes. I have very limited experience with AppleScript, and I've built on Apple's example scripts and the documentation I could find on ADC (which is quite a bit). I may try posting this on Apple's AppleScript mailing list, or I could go create an account on MacOSXHints, if I really have to, but I was hoping someone here might be able to help.
So here's what I want to happen, in English:
So here's what I have so far:
And here's what happens:
Everything works great until it gets to putting the group in for the Bcc recipient. The title that it puts in for the group is "newsletter only, , , , , , , , , , " (with a lot more commas than that), and only the first email from the group is in the email field of the recipient. But if I tell Mail to make a new message with the content being NewsletterRecipients, every single email shows up properly in the content section of the message, surrounded by <> and with a comma and a space in between, which is what Mail wants (i.e.: <email #1>, <email #2>, <email #3>). So I know that my NewsletterRecipients variable (?) is getting to Mail OK.
I'm guessing that the problem has something to do with the text item delimiters business, which I found in what seems to be the main AppleScript documentation (no linkage immediately at hand), which seems to be kind of old. But if I take out the list business and the text item delimiters (so I just have set NewsletterRecipients to value of emails of people of group "newsletter only" as text), the email addresses of the group will be all squashed together (i.e.: email#1email#2email#3), which Mail won't like AFAIK. The only method I could find for getting them separated by a comma and a space and surrounded by <these things> was the text item delimiters business. And even though I set the delimiters back to nothing (which is the default) before I do anything with the title of the recipient, I still end up with all those commas in that title.
Of course, the easiest thing of all would be if I could just tell Mail to create new bcc recipient with properties {group:"newsletter only"}, or something like that. That would be great, but I don't think I can do that: I pored over Mail's AppleScript dictionary, and I couldn't find any hints of a way to access Address Book data and/or Mail's Address Panel (cmd-option-A) via AppleScript without scripting Address Book itself. (And I REALLY don't think I want to get into GUI Scripting.) Using Address Book is fine with me, it's just more of a PITA, and I can't get it to work.
Oh, I should also note that I have not tested the attachment parts of this script. I've used an appropriately modified fragment of it to test the email creation and addressing parts, and I'm assuming (perhaps stupidly) that the attachment part should be no problem, because I've taken it straight from Apple example scripts.
Anyway...any ideas?
TIA
WM
First off, and perhaps most importantly, all this is happening under 10.3.4.
I'm trying to write an AppleScript that I'll use as a PDF workflow option, to help automate the emailing of this newsletter my mom writes. I have very limited experience with AppleScript, and I've built on Apple's example scripts and the documentation I could find on ADC (which is quite a bit). I may try posting this on Apple's AppleScript mailing list, or I could go create an account on MacOSXHints, if I really have to, but I was hoping someone here might be able to help.
So here's what I want to happen, in English:
- My mom goes to the Print dialog, and uses the PDF Workflow menu thingy to select "Email Newsletter" (not the actual name of the script, but it's what I'll use to post here).
- The script creates a new message in Mail, putting my mom's email address with a custom name ("newsletter e-mail list") in the To: field, and a group that we have set up in Address Book ("newsletter only") in the Bcc: field.
- The script attaches the PDF of the newsletter to the email. It does not have to send the email or do anything beyond that.
So here's what I have so far:
Code:
on open these_items
set AppleScript's text item delimiters to {">, <"}
tell application "Address Book"
set NewsletterRecipientsList to value of emails of people of group "newsletter only" as list
set NewsletterRecipients to "<" & (NewsletterRecipientsList as text) & ">"
end tell
set AppleScript's text item delimiters to {""}
tell application "Mail"
set NewsletterMessage to make new outgoing message with properties {visible:true, sender:"my mom's name <mymom'semail@domain.tld>"}
tell NewsletterMessage
make new to recipient at end of to recipients with properties {address:"mymom'semail@domain.tld", name:"newsletter e-mail list"}
make new bcc recipient at end of bcc recipients with properties {name:"newsletter only", address:NewsletterRecipients}
tell content to make new attachment with properties {file:these_items} at after the last paragraph
end tell
activate
end tell
end open
And here's what happens:
Everything works great until it gets to putting the group in for the Bcc recipient. The title that it puts in for the group is "newsletter only, , , , , , , , , , " (with a lot more commas than that), and only the first email from the group is in the email field of the recipient. But if I tell Mail to make a new message with the content being NewsletterRecipients, every single email shows up properly in the content section of the message, surrounded by <> and with a comma and a space in between, which is what Mail wants (i.e.: <email #1>, <email #2>, <email #3>). So I know that my NewsletterRecipients variable (?) is getting to Mail OK.
I'm guessing that the problem has something to do with the text item delimiters business, which I found in what seems to be the main AppleScript documentation (no linkage immediately at hand), which seems to be kind of old. But if I take out the list business and the text item delimiters (so I just have set NewsletterRecipients to value of emails of people of group "newsletter only" as text), the email addresses of the group will be all squashed together (i.e.: email#1email#2email#3), which Mail won't like AFAIK. The only method I could find for getting them separated by a comma and a space and surrounded by <these things> was the text item delimiters business. And even though I set the delimiters back to nothing (which is the default) before I do anything with the title of the recipient, I still end up with all those commas in that title.
Of course, the easiest thing of all would be if I could just tell Mail to create new bcc recipient with properties {group:"newsletter only"}, or something like that. That would be great, but I don't think I can do that: I pored over Mail's AppleScript dictionary, and I couldn't find any hints of a way to access Address Book data and/or Mail's Address Panel (cmd-option-A) via AppleScript without scripting Address Book itself. (And I REALLY don't think I want to get into GUI Scripting.) Using Address Book is fine with me, it's just more of a PITA, and I can't get it to work.
Oh, I should also note that I have not tested the attachment parts of this script. I've used an appropriately modified fragment of it to test the email creation and addressing parts, and I'm assuming (perhaps stupidly) that the attachment part should be no problem, because I've taken it straight from Apple example scripts.
Anyway...any ideas?
TIA
WM