email files put in a folder between certain times

I have a security camera that takes pictures based on motion in our store. I have the camera put the pictures into a pictures folder on our OS X.4 Server. I would like to have any pictures that are added to the folder between the hours of 5:00 pm and 7:00 am emailed to me so I have a record remotely if anyone enters the store after we are closed.

I know you can get object information on individual files, but am not sure how I would select the file to be mailed. Does anyone have an example script that does some sort of similar use that I can look at?

Any help is appreciated.


Hi Fletch,

you can do this with a folder action and this example script.
Replace the lines which set theAddress and theName with your data.
The subject of the mail is “Picture” and the date when the picture has been added to the folder,
you can change this too, if you like.

on adding folder items to this_folder after receiving these_items
	if hours of (current date) > 6 and hours of (current date) < 18 then
		repeat with myFile in these_items
			set theAddress to ""
			set theName to "Jane Doe"
			set theSubject to ("Picture " & (current date) as string)
			set theAttachment to myFile
			tell application "Mail"
				set newMessage to make new outgoing message with properties {subject:theSubject, content:((current date) as string) & return & return}
				tell newMessage
					set visible to true
					make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
					tell content to make new attachment with properties {file name:theAttachment} at after the last paragraph
				end tell
				send newMessage
			end tell
		end repeat
		-- tell application "Mail" to quit -- if Mail should launch and quit every time
	end if
end adding folder items to

Wow! Thanks for the help.


sorry, Fletch, there is a litte mistake I made.
The time window is inverted. It must be

 if hours of (current date) < 8 and hours of (current date) > 16 then

I’m not accustomed to this am/pm stuff :wink:

The AM/PM stuff is odd. We always have to do stuff differently here in the grand ole US of A.

By the way, thank you again for the help! I have it all configured and will let you know if it works.