Hi - can someone tell me how I can loop the following script so it goes through each file one at a time and only does one file attachment per email? - Thanks!!
global default_address
global attachment_name
on adding folder items to this_folder after receiving the_files
try
set attachment_name to name of (info for (the_files’s item 1))
set testing to attachment_name as string
if first word of testing is “4” then
set default_address to {“someone@somwhere.com”}
else if first word of testing is “2” then
set default_address to {“someone_else@somwhere.com”}
else
set default_address to “another@somewhere.com”
end if
set mail_subject to "Mail Subject"
tell me to activate
set the compression_setting to "No"
tell application "Microsoft Entourage"
set MyMessage to make new draft window with properties �
{recipient:default_address, subject:mail_subject, priority:highest, attachment:the_files, content:"Email message body" & return & return & "The attached file is;"}
if class of window 1 is draft news window or class of window 1 is draft window then
tell window 1
try
set theNames to name of every attachment
on error
return -99 -- silent exit
end try
if (count theNames) > 1 then
set messageText to ""
repeat with aName in theNames
set messageText to messageText & return & tab & aName
end repeat
set messageText to messageText & return & return
else if (count theNames) = 1 then
set messageText to return & theNames
end if
set selection to messageText
end tell
end if
send MyMessage
end tell
tell application "Finder"
move the_files to alias "6Gb:Users:server:Desktop:Non PDFs:"
activate
end tell
end try
end adding folder items to
This could be a valid structure:
Pseudo-code:
on adding folder items to this_folder after receiving the_files
repeat with this_file in the_files
set thisFileName to name of (info for (this_file))
--> blah
tell app "Microsoft Entourage" to make new outgoing message at out box folder with properties {blah:"blah", attachments:this_file}
--> blah, blah
end repeat
end adding...
Thanks for that - it “sort of” works. What happens now is that if I drop three files into the watched folder it still attaches three files to the email but sends it three times - so the repeat is working. However, what I want to do is send off one attachment per email, so if I send 10 files for ten different people I get 10 individual emails with one file attached to each. This is the code now;
global default_address
global attachment_name
on adding folder items to this_folder after receiving the_files
repeat with this_file in the_files
set thisFileName to name of (info for (this_file))
try
set attachment_name to name of (info for (the_files's item 1))
set testing to attachment_name as string
if first word of testing is "4" then
set default_address to {"someone@somwhere.com"}
else if first word of testing is "2" then
set default_address to {"someone_else@somwhere.com"}
else
set default_address to "another@somewhere.com"
end if
set mail_subject to "Mail Subject"
tell me to activate
set the compression_setting to "No"
tell application "Microsoft Entourage"
set MyMessage to make new draft window with properties ¬
{recipient:default_address, subject:mail_subject, priority:highest, attachment:the_files, content:"Email message body" & return & return & "The attached file is;"}
if class of window 1 is draft news window or class of window 1 is draft window then
tell window 1
try
set theNames to name of every attachment
on error
return -99 -- silent exit
end try
if (count theNames) > 1 then
set messageText to ""
repeat with aName in theNames
set messageText to messageText & return & tab & aName
end repeat
set messageText to messageText & return & return
else if (count theNames) = 1 then
set messageText to return & theNames
end if
set selection to messageText
end tell
end if
send MyMessage
end tell
tell application "Finder"
move the_files to alias "6Gb:Users:server:Desktop:Non PDFs:"
activate
end tell
end try
end repeat
end adding folder items to
When creating the message, just use “attachment:this_file” instead of “attachment:the_files”
Doh! I should have spotted that - only problem now is that if you drop a group of files at the same time with different numbers it takes the first number and repeats through that. Additionally, it also doesn’t change the attachment name if you drop a group of files - if you drop the files one at a time the script works perfectly though. Also, I’ve simplified it as below as I don’t need to attach the files to send back - I’m about 99% of the way there and any suggestions are greatly appreciated
global default_address
global attachment_name
on adding folder items to this_folder after receiving the_files
repeat with this_file in the_files
set thisFileName to name of (info for (this_file))
set attachment_name to name of (info for (the_files's item 1))
set submitted_file to attachment_name as string
if first word of submitted_file is equal to "9" then
set default_address to {"account1@domain.com"}
else if first word of submitted_file is equal to "8" then
set default_address to {"account2@domain.com"}
else
set default_address to "account3@domain.com"
end if
set mail_subject to "Incorrect File Type"
tell me to activate
tell application "Microsoft Entourage"
set MyMessage to make new draft window with properties ¬
{recipient:default_address, subject:mail_subject, priority:highest, content:"Email Text -" & submitted_file & return & return}
send MyMessage
end tell
tell application "Finder"
move the_files to alias "pathname:"
activate
end tell
end repeat
end adding folder items to