Folder Action Alert with Email

I am super green when it comes to Applescript and scripting in general. Thus far, the only thing I’ve been able to figure out is how to set an ical event to launch a playlist 72 minutes long to play 72 minutes before the end of work… Once the album is finished, it’s time to go home!

Anyways…

I have tried to figure out (via google) how to modify the “add - new item alert” script to do something it doesn’t do by default…

Basically, I want a script that looks in a folder, (I’m using folder actions) and if there is something new in that folder, to send an email… I can figure out how to use Automator to send the email, telling Applescript to launch the email action built with Automator… I just can’t figure out how to tell Applescript to do it… I’ve read a lot in these forums, and I know most of you are brilliant when it comes to this stuff, but I just find myself staring blankly at the screen.

I should probably get a book and learn Applescript the proper way, but that hasn’t happened just yet…

Thanks for any help you guys can give!!!

(Below is a copy of the folder action script I’ve been playing with)


property dialog_timeout : 30 -- set the amount of time before dialogs auto-answer.

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?")
		
		display dialog the alert_message buttons {"Yes", "No"} default button 1 with icon 2 giving up after dialog_timeout
		set the user_choice to the button returned of the result
		
		if user_choice is "Yes" then
			tell application "Finder"
				--go to the desktop 
				activate
				--open the folder
				open this_folder
				--select the items
				reveal the added_items
			end tell
		end if
	end try
end adding folder items to

Browser: Firefox 2.0.0.14
Operating System: Mac OS X (10.5)

Hi,

try this


property theName : "John Doe"
property theAddress : "john@doe.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, ", "}
	set added_Items_List to added_Items_List as text
	set text item delimiters to TID
	set dateString to (current date) as string
	set theBody to "These items have been added to folder " & name of (info for this_folder) & ":" & return & return & added_Items_List
	tell application "Mail"
		set newMessage to make new outgoing message with properties {visible:true, subject:"Folder action alert: " & dateString, content:theBody}
		tell newMessage
			make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
		end tell
		activate
		send newMessage
	end tell
end adding folder items to

Brilliant, Stefan…

Thank you!

Turns out since the images are on a server, everytime the server refreshes, or hiccups… or whatever it is doing…

I get a dozen emails.

Fun!

How would you:

  • Email the notification
    and
  • move the file(s) to another folder (an “outbox”, so that once the email alert has been sent, the original folder is empty, waiting for the next set of files?

Also, would you use automator to make thumbnails as well, or would you use applescript…

Actually, is it possible to send thumbnails of each image in the alert email?

That would be stellar.

Cheers