Sort file by filename

I want to convert this script to sort files by name and send an email to that person. Example if file name is “filename_tw.pdf” then Tim gets an email. If filename is “filename_sw.pdf” then Scott gets and email. I just can’t seem to get the variable to work.

Here is the original script without the variable:


property tim : "tim@email.com"

on adding folder items to this_folder after receiving added_items
	
	set added_Items_List to {}
	repeat with oneItem in added_items
		set end of added_Items_List to name of (info for oneItem)
	end repeat
	set {TID, text item delimiters} to {text item delimiters, return}
	set added_Items_List to added_Items_List as text
	set text item delimiters to TID
	
	
	set Timestamp to do shell script "/bin/date +%m_%d_%y"
	
	tell application "Microsoft Entourage"
		tell (make new outgoing message with properties ¬
			{to recipients:tim, subject:"Job Routing " & Timestamp, content:"Date: " & Timestamp & return & return & "These files have been added to " & this_folder & return & return & "Filename:" & return & added_Items_List as text})
			send
		end tell
	end tell
	
end adding folder items to

Thanks Tim

Hi,

assuming the recipient could be always identified by the last two characters before the name extension (tw or sw)
try this


property addressList : {"tim@email.com", "scott@email.com"}
property nameIndexes : "twsw"

on adding folder items to this_folder after receiving added_items
	repeat with oneItem in added_items
		set {name:Nm, name extension:Ex} to info for oneItem
		set o to (offset of Ex in Nm) - 2
		set nameIndex to text (o - 1) thru o of Nm
		set addressIndex to ((offset of nameIndex in nameIndexes) + 1) div 2
		set theRecipient to item addressIndex of addressList
		set Timestamp to do shell script "/bin/date +%m_%d_%y"
		
		tell application "Microsoft Entourage"
			tell (make new outgoing message with properties ¬
				{to recipients:theRecipient, subject:"Job Routing " & Timestamp, content:"Date: " & Timestamp & return & return & Nm & " has been added to " & (this_folder as text)})
				send
			end tell
		end tell
	end repeat
end adding folder items to

Thanks StefanK, it works great.

How would you add, if filename doesn’t have certain variable (i.e. _tw or _sw) then it sends an email to control email address?

Thanks Tim


property addressList : {"tim@email.com", "scott@email.com"}
property nameIndexes : "twsw"

on adding folder items to this_folder after receiving added_items
	repeat with oneItem in added_items
		set {name:Nm, name extension:Ex} to info for oneItem
		set o to (offset of Ex in Nm) - 2
		set nameIndex to text (o - 1) thru o of Nm
		set addressIndex to offset of nameIndex in nameIndexes
		if addressIndex = 0 then
			set theRecipient to "control@email.com"
		else
			set theRecipient to item ((addressIndex + 1) div 2) of addressList
		end if
		set Timestamp to do shell script "/bin/date +%m_%d_%y"
		
		tell application "Microsoft Entourage"
			tell (make new outgoing message with properties ¬
				{to recipients:theRecipient, subject:"Job Routing " & Timestamp, content:"Date: " & Timestamp & return & return & Nm & " has been added to " & (this_folder as text)})
				send
			end tell
		end tell
	end repeat
end adding folder items to

Awesome your the best Thanks