Time-lapse photos via iSight and AppleScript

Posted July 24, 2009 by Timmargh
Categories: Automated, Photography

Tags: , ,

I wanted to try some time-lapse photography using my shiny new HD camcorder, but it turns out it doesn’t seem possible using Mac OS X (boo!), so I turned my attention to the built-in iSight in my MacBook Pro instead. The image quality will be much lower, obviously, but I figured it’d be good fun to try until I figure a way to use my camera proper.

After trying and failing to write working AppleScripts and Automator workflows to take photos with the iSight and save them with sequential filenames, I came across iSightCapture, a command line utility that, with the correct parameters, would do the job I needed. Luckily, during the same search I also found the AppleScript I would need to make things easier from neoporcupine — his post goes into great detail on how to automate taking photos at regular intervals for security and other purposes, but I’m just aiming for a ‘click and go’ approach.

After downloading, unZIPping and copying iSightCapture to our desired location (I just put it in the main Applications folder), we need to amend the AppleScript we borrowed from neoporcupine, e.g:

repeat 3000 times
  do shell script "/Applications/isightcapture ${HOME}/Pictures/Lapse/snap`date '+%y%m%d%H%M%S'`.jpg"
  delay 5
end repeat

Going line-by-line we have:

  1. the number of photos to take, e.g. 3000;
  2. taking the photo and saving it — the above example saves it to ‘Pictures/Lapse’ in my home folder and adds the date and time in the format YYMMDDHHMMSS;
  3. the gap between photos, e.g. five seconds;
  4. the end of the loop.

(With the sequential naming of the file, I’m obviously not expecting to make sequences that last months or years, but if it was running at midnight on New Year’s Eve then obviously the day, month and year would change and the files need to be kept in sequence.)

Copy and paste that into Script Editor, change whatever values you need to make it fit your requirements and save it. You may want to test it at this point, too. If you’re just going to run this script straight from Script Editor (which is what I did) then you can skip the next parts and go straight to the bit involving QuickTime. Otherwise, read on …

To get your time-lapse sequence to start at a specified time automatically, e.g. to catch the sunrise while you’re still in the land of nod, then we need to set up a reminder in iCal — you can use alternative methods of course, such as Proxi, but iCal’s easy, simple and is already installed on all modern Macs. (The only problem with this method is that it can be difficult to stop a script once it’s running in the background as there’s big red STOP! button anywhere.) So, just create an event for the day and time you want the script to start and make sure you add an alarm to run the script itself at the time of your choosing, e.g.:

iCal time-lapse capture event

iCal time-lapse capture event

You can also set your Mac to wake up at the appropriate time if it’s running on battery or you simply don’t want it left on beforehand — just go into System Preferences -> Energy Save -> Schedule and make the appropriate changes:

Energy saver schedule settings

Energy saver schedule settings

The next step is to position your Mac (which, in my experience, was a bit difficult unless you open up Photo Booth to get an idea of what the camera can see, but don’t forget to quit it when you’re done otherwise iSightCapture will fail) and then … wait.

It’s worth mentioning at this point that iSightCapture did occasionally fail for no apparent reason, reporting that the camera lens couldn’t be opened, which I’m assuming is a generic “I can’t get the camera working!” error message.

Once your capture is complete, you should hopefully have a folder full of photos, all nicely named in sequence, so if that was your goal then you’re done. If, like me however, you want to make them into a movie then read on …

Open QuickTime Player and select ‘Open Image Sequence…’ from the File menu, navigate to the folder where your photos are stored, select the first one and click ‘Open’. Select a frame rate (I chose ‘24 frames per second’) and QuickTime will make a movie of your photos.

You can save it now as is, but it’s uncompressed and, depending on the number of photos, may result in a very large file. I usually choose ‘Export…’ from the File menu, select ‘Movie to QuickTime Movie’ and ‘Default Settings’ which gives a reasonable quality output. You can then do whatever else you desire with the final file, such as editing together a few of them, adding some music and uploading it to YouTube:

If you find any of this useful and do actually make a movie, then please leave me a comment with a link. Cheers!

Use an alias as a discreet reminder

Posted June 9, 2009 by Timmargh
Categories: Automated

Tags:

(This was a personal favourite from my old site.)

I have a number workflows and applications I run at regular and varying times on my MacBook to backup my files and to keep things running smoothly, so I need a way to either run these tasks automatically or to remind me to run them myself.

The logical solution would be to simply set a reminder in iCal, or another scheduling capable app such as Proxi, to launch whichever workflow or app at the specified time. But one or two of the tasks in question require internet access and, being a creature of habit, I always turn off my wireless connection if I’m running on the battery and don’t need network access. There’s also the likely possibility that I’m in the middle of something and I don’t want another process starting-up in the middle of it.

Another thing to consider, at least in my world, is that other people use my MacBook too and quite often it’s simply to browse the web and/or check their email, so nine times out of ten it’s easier to just slide it across to them rather than logging out and into their own or the guest account.

So, how can I get iCal (or Proxi etc.) to remind me to run a workflow in a discreet and not-easy-to-cancel-and-forget way?

The solution I came up with that I liked the most was to write a short and simple script to create an alias to the workflow and place it on the desktop. That way the next time I see the desktop I’ll also see the alias and can simply double-click it, and when it’s done I can drop the alias into the trash — there’s no interruption when the reminder time comes around and there’s no pop-up to cancel and forget.

Open up Script Editor and enter something like:

set workflow to "Mac OS X:Users:yourshortname:Documents:Automator:Backup to iDisk.app"
set alias_path to "Mac OS X:Users:yourshortname:Desktop:"
set alias_name to "Backup to iDisk"
set alias_full to (alias_path & alias_name)

tell application "Finder"
  if not (exists file alias_full) then
    make new alias file to file workflow at desktop with properties {name:alias_name}
  end if
  set label index of file alias_name to 2
end tell

The line set label index … changes the colour label for the alias’ icon and is entirely optional — alter the number to anything from 1 to 7 for orange, red, yellow, blue, purple, green or grey respectively. Remember to replace the names and paths in the first three lines with your equivalents.

To schedule the running of this script, simply create an event or reminder in your preferred scheduling app; in iCal you’d need something like:

iCal event to run 'Create alias' script

iCal event to run 'Create alias' script

And that’s about it. Try it out, change it for your purposes and feel free to offer suggestions for other uses and/or improvements.

What can you expect to see?

Posted June 2, 2009 by Timmargh
Categories: Uncategorized

Well, if all goes according to plan then I shall be charting my attempts to “do stuff” with Mac OS X.

Primarily I shall be updating some of my favourite posts from my old ‘blog whilst (hopefully) throwing in some new ideas.

Watch this space and please: feel free to join in with ideas, criticism or downright abuse.