Newbie file extension and filename question

Hi Everybody,

I am a real newbie at applescript, and i have been using some of the provided scripts to get myself started. I want finder to watch a folder and send an email when files are added to it. So I am using folder actions with some generic applescript. But the folder is a downloads folder for videos, so files initially get put in as movie.ext.downloading and I want the email only to send for files that do NOT have the .downloading extension on them. On top of this, I want the email to include the filename that has downloaded (right now it is just a generic “a file has been added”). Can anyone help? Here is the script I am starting with:

on adding folder items to this_folder after receiving added_items
	try
		tell application "Finder"
			--get the name of the folder
			set the folder_name to the name of this_folder
		end tell
	
					
			-- find out how many new items have been placed in the folder
			set the item_count to the number of items in the added_items
			--create the alert string
			set alert_message to ("Folder Actions Alert:" & return & return) as Unicode text
			if the item_count is greater than 1 then
				set alert_message to alert_message & (the item_count as text) & " new items have "
			else
				set alert_message to alert_message & "One new item has "
			end if
			set alert_message to alert_message & "been placed in folder " & «data utxt201C» & the folder_name & «data utxt201D» & "."
			-- set the alert_message to (the alert_message & return & return & "Would you like to view the added items?")
			
			tell application "Mail"
				(* SPECIFY GENERAL CONTENT OF MESSAGE *)
				set bodyvar to return & return & "Test body."
				set addrVar to "myemail@myemail.com"
				set addrNameVar to "Me"
				set subjectvar to "Test Message"
				
				(* CREATE THE MESSAGE *)
				set composeMessage to make new outgoing message -- (a reference to (make new compose message at beginning of compose messages))
				tell composeMessage
					make new to recipient at beginning of to recipients with properties {address:addrVar}
					set the subject to subjectvar
					set the content to alert_message
				end tell
				send composeMessage
			end tell
					
	end try
end adding folder items to

I have been trying things like

	if file type of (info for this_item) is not "downloading "

but I think I must be on the wrong track as none of my trying has gotten me anywhere…

I am OS 10.4.9.
Thanks a lot in advance!
j

I would go about this a little bit different since the files are still downloading after they added to the folder I personally would make a stay open app that check a folder every so often for files in a valid property list then process only the valid files here is an example of getting only valid files


property ValidImageFiles : {"PSD", "JPG", "JPEG", "TIFF", "TIF", "EPS", "GIF", "PDF", "BMP"}
set aFolder to choose folder
tell application "Finder"
	set ImageFiles to (every file in folder aFolder whose name extension is in ValidImageFiles)
end tell

Hi,

does it really matter, whether the file has been already downloaded to send the mail?

this script processes only files with the extension “download”,
strips the extension form the file name (which results the original file name)
and sends the mail with the message “ has been added to folder ” as subject


on adding folder items to this_folder after receiving added_items
		repeat with i in added_items
			set {Nm, Ex} to {name, name extension} of (info for i)
			if Ex is "download" then
				set Nm to text 1 thru -10 of Nm -- strip ".download" from file name
				tell application "Mail"
					set addrVar to "myemail@myemail.com"
					set subjectvar to Nm & " has been added to folder " & name of (info for this_folder as alias)
					set composeMessage to make new outgoing message with properties {subject:subjectvar}
					tell composeMessage
						make new to recipient at beginning of to recipients with properties {address:addrVar}
					end tell
					send composeMessage
				end tell
			end if
		end repeat
end adding folder items to

Thank you both very much for this help! I ended up using what Stefan had sent me and just reversing it so that the email ONLY goes out if the extension is NOT “downloading”. This is a script that can be used in conjunction with the free application Pando (pando.com) that allows you to share big files via email. I wanted to create this script so that I didn’t have to be at the machine where the RSS download is happening and can still find out when it’s done. So this is perfect! Here’s what I used in the end (very minimal changes to what Stefan wrote):

(*
This folder action watches the Pando downloads folder. For every completed file, it sends an email to the specified address to tell them the download is complete.
*)

on adding folder items to this_folder after receiving added_items
	repeat with i in added_items
		set {Nm, Ex} to {name, name extension} of (info for i)
		if Ex is not "downloading" then
			
			tell application "Mail"
				set addrVar to "email@myemail.com"
				set subjectvar to Nm & " download complete"
				set alert_message to Nm & " has finished downloading. It has been added to folder " & name of (info for this_folder as alias) & "."
				set composeMessage to make new outgoing message with properties {subject:subjectvar}
				tell composeMessage
					make new to recipient at beginning of to recipients with properties {address:addrVar}
					set the content to alert_message
				end tell
				send composeMessage
			end tell
		end if
	end repeat
end adding folder items to

Thanks again,
j