folder actions by file type.

I need to set up a watched folder(s) on a server that does the following:

1.) Subject is file name of dropped item.

2.) if the file name contains the letters ABCxxxxxxxxx.pdf, or DEFxxxxxxxxx.pdf, etc. then
email these recipients: person1@company.com; person2@company.com

else (but)

if the file name contains the letters LMNxxxxxxxxx.pdf, or OPQxxxxxxxxx.pdf, etc. then
email these recipients: person3@company.com; person4@company.com

The file name length would be a variable in this.
Also, what would I script if not everyone is using the same mail app?

I would appreciate any help on this. Thank you.

N

The mail app used by the recipient doesn’t matter.



on adding folder items to this_folder after receiving these_items
	
	repeat with aFile in these_items
		tell application "Finder" to set aName to name of aFile
		
		if aName does not end with ".pdf" then exit repeat
		set b3 to text 1 thru 3 of aName
		if b3 is in {"ABC", "DEF"} then my sendToRecipient1(aFile)
		if b3 is in {"LMN", "OPQ"} then my sendToRecipient2(aFile)
	end repeat
end adding folder items to

on sendToRecipient1(f)
	-- here put the code to send file f to this recipient
end sendToRecipient1

on sendToRecipient2(f)
	-- here put the code to send file f to this recipient
end sendToRecipient2

Yvan KOENIG (from FRANCE jeudi 14 mai 2009 22:43:20)

Just a few modifications to Yvan’s post

on adding folder items to this_folder after receiving these_items
	tell application "Finder"
		repeat with aFile in these_items
			set aName to name of aFile
			if aName ends with ".pdf" then
				set b3 to text 1 thru 3 of aName
				if b3 is in {"ABC", "DEF"} then my sendToRecipient(aFile, {"person1@company.com", "person2@company.com"})
				if b3 is in {"LMN", "OPQ"} then my sendToRecipient(aFile, {"person3@company.com", "person4@company.com"})
			end if
		end repeat
	end tell
end adding folder items to

on sendToRecipient(f, sendTo)
	-- here put the code to send file f to this recipient
end sendToRecipient

This way you are only using one tell to the “Finder” and you would only need to have one routine to send mail

Thank you guys!

So if not everyone is using Entourage, this won’t matter? Could people on Windows machines get emails too?

N

Email client and operating system do not matter. I think this is where your confusion is at. When the folder action script fires off this is happening on the server not on the client side. So the server is what’s going to be doing on the mailing not the individual clients that are uploading the files.

Okay thanks again and forgive my ignorance. You’re right I am getting confused between the server and client sides.
Is there a more reliable or faster way to send mail other than Tell application “Entourage”, “Mail”?

Can I use Terminal?

Thanks again.

N

Quote yes you can use the mail command from the terminal via the applescript to send the mail. Check out man:mail for more information. Depending on a number of factors though it will work out of the box or you may need to do additional configuration.