Hi
I’m trying out subroutines for the first time but can’t get it to work - when a condition is met it goes to the subroutine, however, the script then appears to stop. How do I get it to continue the script with the result of the subroutine?
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))
if first word of thisFileName is "CR" or "R" then
CR_email()
else if first word of thisFileName is not "CR" or "R" then
Normal_email()
end if
try
set attachment_name to name of (info for (the_files's item 1))
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 outgoing message with properties ¬
{recipient:default_address, subject:mail_subject, priority:highest, content:"Message text"}
send MyMessage
end tell
tell application "Finder"
move the_files to trash
activate
end tell
end try
end repeat
end adding folder items to
on CR_email()
if second word of thisFileName is "1" then
set default_address to {"emailaddress1@domain.com"}
else
set default_address to {"emailaddress2@domain.com"}
end if
end CR_email
on Normal_email()
if first word of thisFileName is "1" then
set default_address to {"emailaddress1@domain.com"}
else
set default_address to {"emailaddress2@domain.com"}
end if
end Normal_email :?
Does this work? I can’t test it due to the lack of Entourage. Note: I don’t see where you are using attachment_name.
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))
if thisFileName starts with "CR" or "R" then
CR_email(thisFileName)
else if thisFileName does not start with "CR" or "R" then
Normal_email(thisFileName)
end if
try
set attachment_name to name of (info for (the_files's item 1))
set mail_subject to "Mail Subject"
set the compression_setting to "No"
tell application "Microsoft Entourage"
set MyMessage to make new outgoing message with properties ¬
{recipient:default_address, subject:mail_subject, priority:highest, content:"Message text"}
send MyMessage
end tell
end try
end repeat
tell application "Finder"
move the_files to trash
activate
end tell
end adding folder items to
on CR_email(name_)
if second word of name_ is "1" then
set default_address to {"emailaddress1@domain.com"}
else
set default_address to {"emailaddress2@domain.com"}
end if
end CR_email
on Normal_email(name_)
if first word of name_ is "1" then
set default_address to {"emailaddress1@domain.com"}
else
set default_address to {"emailaddress2@domain.com"}
end if
end Normal_email
Thanks for that Rob!! - works perfectly!!
The attachment_name is used by part of the script I didn’t post that emails copies of the file back to the user
Cheers
Howard