How do I setup a mail notification after receiving items into a folder

Hi,

I am struggling trying to identify why my mail continues to email me when an item is added through FTP to a folder before it has finished receiving it. Also how do I set the item to be invisible until it is fully received.

Help would be much appreciated.

Thanks
Andy

PS here is my code:

on adding folder items to this_folder after receiving added_items
	tell application "Mail"
		activate
		set theContent to "New files have arrived on ftp: " & added_items as text
		set theSub to "New files have arrived on ftp"
		set this_message to make new outgoing message at end of outgoing messages with properties {subject:theSub, content:theContent, visible:true}
		tell this_message
			--set visible to false
			set theAddress to "pdrepro@wyndeham.co.uk"
			set theName to "mail"
			make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
			send this_message
		end tell
	end tell
end adding folder items to

Hi lonedeveloper:

This what I use:

property theSignature : "mySignature" -- name of the Mail signature
property theGroup : "Whatever" -- name of the Address Book group

on adding folder items to this_folder after receiving these_items
	tell application "Address Book" to set theRecipients to value of emails of people of group theGroup
	tell application "Mail" to set messageSignature to signature theSignature
	repeat with i in these_items
		set fileName to name of (info for i)
			delay 5 --> Works for me but you can give in a higher value
			set posixpath to quoted form of POSIX path of i
			set fileSize to item -1 of paragraphs of (do shell script "du -hc " & posixpath & " | awk '{print $1}'") as text
			set fnamepath to quoted form of (text 1 thru ((offset of "." in fileName) - 1) of fileName)
			tell application "Mail"
				tell (make new outgoing message with properties ¬
					{visible:true, subject:"blabla: " & fnamepath, content:" " & "\n" & (this_folder as text) & "  " & fileName & "\nFileSize: " & fileSize & "b"})
					repeat with oneRecipient in theRecipients
						make new to recipient at end of to recipients with properties {address:item 1 of oneRecipient}
					end repeat
					set message signature to messageSignature
					send
				end tell
			end tell
	end repeat
end adding folder items to

Works for me

–Peter–

Can this be used with Entourage?

Hi retepp,

Thanks for the script, I have modified and tried script, but I have found a few problems.

The delay when activated used max CPU usage in system events for as long as the delay value.
Also file size accumulates when other files are sent giving incorrect file size after the first received mail

I am not sure where the problem lies…!

I am looking to send an email after files have been received and for those files to be invisible in the receiving folder until it has fully transfered.

property theSignature : "FTPemailsig" -- name of the Mail signature
property theGroup : "FTPGroup" -- name of the Address Book group

on adding folder items to this_folder after receiving these_items
	tell application "Address Book" to set theRecipients to value of emails of people of group theGroup
	tell application "Mail" to set messageSignature to signature theSignature
	repeat with i in these_items
		set fileName to name of (info for i)
		delay 300 --> delay in seconds
		set posixpath to quoted form of POSIX path of i
		set fileSize to item -1 of paragraphs of (do shell script "du -hc " & posixpath & " | awk '{print $1}'") as text
		set fnamepath to quoted form of (text 1 thru ((offset of "." in fileName) - 1) of fileName)
		tell application "Mail"
			tell (make new outgoing message with properties ¬
				{visible:true, subject:"New files have arrived on FTP " & fnamepath, content:"New files have arrived on FTP " & "
" & (this_folder as text) & "  " & fileName & "
FileSize: " & fileSize & "b"})
				repeat with oneRecipient in theRecipients
					make new to recipient at end of to recipients with properties {address:item 1 of oneRecipient}
				end repeat
				set message signature to messageSignature
				send
			end tell
		end tell
	end repeat
end adding folder items to

Hi,

Take a look at: http://macscripter.net/viewtopic.php?id=18653

–Peter–

Thanks Peter,

Will take a look, thanks for your help.

Andy