Jump to content
Sign in to follow this  
forbade

Applescript (Select & Email multiple attachments interactively)

Recommended Posts

forbade

This will send an email with as many attachments as you wish.

 

Create a script that has an Perform Applescipt step, then just put your modified version of the following code in the calculated script option.

 

You can attach more than just pictures.

 

(note the reason for the substitute function for the email body field, is to remove quotation marks.)

------------

"display dialog \"Do you want to add pictures to this email\" buttons {\"Yes\", \"No\"}"&¶&

"set whatIS to result"&¶&

"set theCHOICE to button returned of whatIS"&¶&

"if theCHOICE = \"Yes\" then"&¶&

" set theCHOICE to \"Yes\""&¶&

" set pictureLIST to {}"&¶&

" repeat until theCHOICE = \"No\""&¶&

" choose file with prompt \"select file\""&¶&

" set currentFileName to result -- & \",\""&¶&

" copy currentFileName to the end of pictureLIST"&¶&

" display dialog \"Do you need to add another picture? \" buttons {\"Yes\", \"No\"}"&¶&

" set whatIS to result"&¶&

" set theCHOICE to button returned of whatIS"&¶&

" end repeat"&¶&

" set emailPICS to \"Yes\""&¶&

"else"&¶&

" set emailPICS to \"Nope\""&¶&

"end if"&¶&

"------"&¶&

"tell application \"Mail\""&¶&

" activate"&¶&

" set Contact_Email to \"MAIN::email_address\""&¶&

"set Sending_Account to \""&MAIN::email_account&"\""&¶&

"set Email_Subject to \""&MAIN::email_subject&"\""&¶&

" set Email_Body to \"" & ¶&

Substitute(MAIN::email_body;["\"";"\\\""];["\”";"\\\""])&"\""&¶&

" set NewQuote to (make new outgoing message with properties {visible:true, subject:Email_Subject, sender:Sending_Account, content:Email_Body})"&¶&

" tell NewQuote"&¶&

" make new to recipient with properties {address:Contact_Email}"&¶&

" if emailPICS = \"Yes\" then"&¶&

" repeat with att in pictureLIST"&¶&

" make new attachment with properties {file name:att} at after the last paragraph"&¶&

" end repeat"&¶&

" else"&¶&

" do shell script \":\""&¶&

" end if"&¶&

" --send"&¶&

" end tell"&¶&

"end tell"

----

 

it is possible to send multiple people the multiple attachments .

 

I export a found set of emails to a csv file and then have the applescript load them via the shell.

the csv file had two fields the first for the name of the recipient if there is one, and the second for the address.

 

this part of the other script loads the email addresses to be used by the applescript.

"set emailLIST to (do shell script \"cd /email ; export LC_ALL='C' ; cat email_list_concise.csv | cut -d ',' -f 2 | awk '{printf $0\\\",\\\"}' | sed '/^$/d'\")"&¶&

explanation of pipe steps:

"/email" is the directory that the list of exported email address are in.

"email_list_concise.csv" is the name of the file with the email addresses.

the "cut" step only loads the address field.

the "awk" & "sed" step prepares the address for the applescript.

 

here is the entire script step

---------

"display dialog \"Do you want to add pictures to this email\" buttons {\"Yes\", \"No\"}"&¶&

"set whatIS to result"&¶&

"set theCHOICE to button returned of whatIS"&¶&

"if theCHOICE = \"Yes\" then"&¶&

" set theCHOICE to \"Yes\""&¶&

" set pictureLIST to {}"&¶&

" repeat until theCHOICE = \"No\""&¶&

" choose file with prompt \"select file\""&¶&

" set currentFileName to result -- & \",\""&¶&

" copy currentFileName to the end of pictureLIST"&¶&

" display dialog \"Do you need to add another picture? \" buttons {\"Yes\", \"No\"}"&¶&

" set whatIS to result"&¶&

" set theCHOICE to button returned of whatIS"&¶&

" end repeat"&¶&

" set emailPICS to \"Yes\""&¶&

"else"&¶&

" set emailPICS to \"Nope\""&¶&

"end if"&¶&

"------"&¶&

"------"&¶&

"set emailLIST to (do shell script \"cd /email ; export LC_ALL='C' ; cat email_list_concise.txt | cut -d ',' -f 2 | awk '{printf $0\\\",\\\"}' | sed '/^$/d'\")"&¶&

"set AppleScript's text item delimiters to {\",\"}"&¶&

"set emailITEM to every text item of emailLIST"&¶&

"tell application \"Mail\""&¶&

"activate"&¶&

"repeat with currentVALUE in emailITEM"&¶&

"set Contact_Email to currentVALUE" &¶&

"set Sending_Account to \""&MAIN::email_account&"\""&¶&

"set Email_Subject to \""&MAIN::email_subject&"\""&¶&

"set Email_Body to \"" & ¶&

Substitute(MAIN::email_body;["\"";"\\\""];["\”";"\\\""])&"\""&¶&

"set NewQuote to (make new outgoing message with properties {visible:true, subject:Email_Subject, sender:Sending_Account, content:Email_Body})"&¶&

"tell NewQuote"&¶&

"make new to recipient with properties {address:Contact_Email}"&¶&

"if emailPICS = \"Yes\" then"&¶&

" repeat with att in pictureLIST"&¶&

" make new attachment with properties {file name:att} at after the last paragraph"&¶&

" end repeat"&¶&

" else"&¶&

" do shell script \":\""&¶&

" end if"&¶&

"delay 1"&¶&

"send"&¶&

"end tell"&¶&

"end repeat"&¶&

"end tell"

Share this post


Link to post
Share on other sites
AHunter3
This will send an email with as many attachments as you wish.

 

If you use Apple Mail as your email program it will, at any rate. Or your end users all do so.

 

OK, snarkiness about that aside, cool trick!

Share this post


Link to post
Share on other sites
Smighter

forbade, how would I change your script to read a csv file for the email address and attachment? I'm needing to email users their own file. I have a csv file with there email address and the their file. Emailing it by hand would normally be easy but I'm needing to email about 2500 files out to 2500 people.

Share this post


Link to post
Share on other sites
rpaulh

This is an old post so I hope someone will see this. I am not a true applescript developer so I need some guidance. The above script for multiple attachments has quotes at the beginning & end of each line as well as the other characters at the end of each line. I have removed all of these as well as replacing \" with ". The one that throws me is the Substitute(Main::email_body) step, I do not know what the parameters are supposed to be in the brackets. Can anyone offer any insight. Thanks

 

Edited: Think I figured out the character issues within FileMaker. Now have a new issue, FM does not seem to recognize the "set NewQuote to" function. It returns "function not found" when I try leave the calculation page.

Share this post


Link to post
Share on other sites
rpaulh

AHunter3, I'm on an old post and noticed you are online from a reply you posted there. Can you look at my post from today and see if you can offer any assistance? Thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  



×
×
  • Create New...

Important Information

Terms of Use