Need a solution for emailing/ftping file modification info...

Hi

I have recently setup a remote timelapse recording system using a macbook and a canon eos 350dslr. The macbook triggers the canon every 5 minutes to take a shot, then saves the image to a “still captures” folder. This system is setup in a remote location and connected to a wireless internet connection, so I can VNC in remotely to control the system.

I have scripted a bunch of automator workflows to control backing up images, ftping them to the internet etc.

However, the remote capture software I’m using tends to lock up at random, sometimes after a few days, sometimes only a few hours.

So I tried to code something in automator to send me a confirmation every 30 minutes to confirm that new images were being captured. Unfortunately the only solution I had was to get a screengrab every 30 mins with the “still captures” folder open on the desktop so I could see when the latest images were captured. Unfortunately this didn’t work, and is a little bit unwieldy anyway.

What I would really like is a routine that got the “last modified” info from the “still captures” folder and either emailed or ftpd the result to my email account every 30-60 mins. Then I would have a constant indicator of whether new images were being added to the folder.

A sweetener to this would be if the routine was clever enough to identify when 10 minutes had passed without a new file added to the “still captures” folder, and then email me with the subject line “NO CAPTURES FOR LAST 10 MINUTES!!” so I would know straight away when there was a problem.

I was tempted to start teaching myself applescript and write a routine myself, however I figure that’s going to take me days/weeks, when I’m sure there’s someone here who could knock it together in an hour.

Is there anyone prepared to give it a go? I would be prepared to offer some financial compensation for your time if you want to give me an estimate of how much it might cost. Or if it can be mashed together using existing subroutines, I might be able to figure that out myself.

Cheers
Chris

This is the gist of what you want. Save as a application and with the stay open option selected. I would probable make this a startup item or something or launch it as part of your workflow.

property watchedFolder : ((path to desktop as Unicode text) & "Captured")

on idle
	set triggerTime to (current date) - (10 * minutes)
	tell application "Finder"
		if (modification date of folder watchedFolder) < triggerTime then
	-- here is where we would handle the notification
		end if
	end tell
	return 600
end idle

As for handling the notify how would you prefer to handle it?

An even better idea than notifying you though would probably be to just relaunch the locked application. (And possibly notify you)

Another alternate solution is to rather than utilize an idle handler is to make a one-run version and have it run every 10 minutes via a launchd job.

Hi James

Thanks for that. I would probably prefer that the script emailed me for the notify because i’m more likely to check my mail regularly than an ftp site…

I’m not familiar with launchd jobs, but I think a looped applescript should work fine for now…

Chris.

Okay - so starting out with what you have given me, I experimented with adding some code to get the system smsing me (via SMS Mac Scripting). The SMS Mac code definitely works, but I couldn’t get it to send the sms when a folder had no modifications for 10 minutes. Have I specified the path incorrectly? (Assuming the folder I want to watch is called “Captures” in the Documents folder in the user “timelapse”?)


property watchedFolder : (("Timelapse:Users:timelapse:Documents:") & "Captures")

on idle
	set triggerTime to (current date) - (10 * minutes)
	tell application "Finder"
		if (modification date of folder watchedFolder) < triggerTime then
			tell application "SMS Mac Scripting"
				set m to make new outgoing sms with properties {flash:false}
				tell m
					set message to "No Image for 10 mins!"
					set recipients to {"+61414900000"}
					try
						send
					on error errMsg number errNum
						display dialog "Error: " & errNum & ". " & errMsg
					end try
				end tell
			end tell
		end if
	end tell
	return 600
end idle

Just to verify… you saves this from script editor as an application and the the options “Stay Open” selected and then double clicked the application to run it right?

If you actually run the script from Script Editor it will not work… you need to save it as an app and then launch the app.

Ah, yeah I was trying the script from the script editor.

I’ll try saving as an application…

Brilliant! Thats now working perfectly. Thanks!

It`s also opened up a bunch of possibilities that I think I can explore myself… I think I should be able to make it so the notification SMSs me the last modification time, and probably even the time that has elapsed since then.

I’m also thinking I could make it email me as well as sms, just in case the sms system fails for one reason or another (most likely running out of sms credit!)

Thanks again for your help.

Chris

Are you gentlemen hip to Cronnix? It’s a simple GUI providing access to your Mac’s ‘cron’ command and it’s now my favorite way to schedule script executions. Check it out - it’s freeware and it works great!

http://www.abstracture.de/projects-en/cronnix

On Tiger and Leopard servers I would recommend launchd over cron as thats the direction Apple is taking. Lingon is a opensource tool to help create the launchd files.

Glad to be of help! Make sure you come back and post your finished solution so others here, who may one day find themselves in a similar boat, can learn from it! And of course if you have additional questions just ask =)

Ok, I thought I could figure it out, but I am stumped. I wanted to include the modification date in the subject line of the email I was sending and in an sms, but I keep getting a “Expect “,” but found identifier” error… I expect that its because the mod date is not actually a string?

This is the snippet causing me trouble.


property watchedFolder : "Timelapse:Users:timelapse:Documents:Captured"

			tell application "Mail"
				set theMessage to make new outgoing message with properties {visible:true, subject:"No new image since " & ((modification date of folder watchedFolder) as string) & " at " (current date), content:"content"}
				tell theMessage
					make new to recipient at end of to recipients with properties {name:"Chris Tomkins", address:"timelapse@timelapses.com"}
				end tell
				send theMessage
			end tell

The two problems I see are that in one spot you are missing a ‘&’ and that you should get the modification date as string before stepping into the mail tell, so something like this.

tell application "Finder" to set modDate to modification date of folder watchedFolder as string
tell application "Mail"
	set theMessage to make new outgoing message with properties {visible:true, subject:"No new image since " & modDate & " at " & (current date), content:"content"}
	tell theMessage
		make new to recipient at end of to recipients with properties {name:"Chris Tomkins", address:"timelapse@timelapses.com"}
	end tell
	send theMessage
end tell

And id that email address is real my apologies for sending you a message… I forgot to comment out the send line LOL.

Excellent. Its working great now.

So here’s the script that works…


property watchedFolder : "Macintosh HD:Users:timelapse:Documents:still captures:still originals"

on idle
	set triggerTime to (current date) - (10 * minutes)
	tell application "Finder" to set modDate to modification date of folder watchedFolder as string
	tell application "Finder"
	
		(* If no images have been taken for the last 10 minutes then... *)
		if (modification date of folder watchedFolder) < triggerTime then
		
			(* Send me an SMS with last known folder mod time *)
			tell application "SMS Mac Scripting"	
				set m to make new outgoing sms with properties {flash:false}
				tell m
					set message to "No still image since " & modDate & " at " & (current date)
					set recipients to {"+61414999999"}
					try
						send
					on error errMsg number errNum
						display dialog "Error: " & errNum & ". " & errMsg
					end try
				end tell
			end tell				

			(* And send me an email with last known folder mod time *)	
			tell application "Mail"
				set theMessage to make new outgoing message with properties {visible:true, subject:"TIMELAPSE ALERT - No still image since " & modDate & " at " & (current date), content:"No still image since " & modDate & " at " & (current date)}
				tell theMessage
					make new to recipient at end of to recipients with properties {name:"Chris Tomkins", address:"email@notrealemail.com"}
				end tell
				send theMessage
			end tell
		end if
	end tell
	
	(* Wait 20 minutes before checking again *)
	return 1200
end idle

The scary thing about this script at the moment is that you have no idea its running until something goes wrong. It’d be great to have a visual cue on the desktop, like a dialogue box that said something like “Next Check: Thursday, 24 April 2008 11:41:42 PM”, just to know its running… ? Is that easy to do?