I went looking for a way to capture photos from a webcam into a FileMaker container field on a Macintosh. The plugin options were not as good as I thought they might be, but there was a happy ending to my search. I came up with a free way to snap photos right into FileMaker Pro.
Download Demo File
I have a solution called PassTracker that keeps track of member activity at climbing gyms. A while back I integrated a USB camera to take customer photos. I was employing an AppleScript that sends a request to a third-party program called Periscope from Freeverse. Recently Periscope started to load very slowly, so my customers asked for a fix. Looking for an upgrade, it appears Freeverse doesn’t list Periscope on their web site anymore, so I have to assume it is no longer being supported.
The Periscope solution had never been the ideal for PassTracker as the external interface with its detailed control of the webcam was overkill for my users. It seems to me a bit strange that FileMaker Go running on iOS has built-in image capture capability and every laptop and all-in-one computers sold in the last five years has some kind of camera built-in, but FileMaker Inc. has not added a video capture capability to FileMaker Pro yet. Another feature for FileMaker 13 perhaps?
My past experience with Troi’s software has been good—they create plugins that are both affordable and well behaved. In this case however the price tag was too high for my solution. For some reason Troi charges $1,049 for a developer license and they don’t sell individual licenses.
I didn’t have much success getting VideoRaptor’s plugin running. At first I got errors saying there was no license code installed, but it hadn’t asked for that on loading. Once I installed a trial license, the plugin came back with more errors saying something about an upgrade. VideoRaptor has a low price ($27), but I was not able to get it working. Apparently a new version is in the works, so it may be worth revisiting.
Automator to the Rescue
I researched some more and came across an article on TUAW.com about using Automator to snap a photo. It turns out there is a nice little step built into Automator to snap a photo with your webcam. Automator is an automation utility that is available on all current Mac OS X computers.
FileMaker calls the Automator Routine
With that knowledge in hand, I turned to FileMaker to generate a script that would launch the Automator routine, wait for a set period while the photo was taken and then import the resulting image from the Desktop into FileMaker Pro.
Automator routine to grab an image from a USB Camera attached to your Mac.
The three steps I used in the Automator routine are:
- Take Video Snapshot
- Apply Quartz Composition Filter to Image Files
- Change Type of Images
The Automator script can be as fancy or as simple as you like.
1) The simplest would just be use the first step, take a photo. I added two more steps to make the image smaller.
2) The first additional step shrinks the image dimensions down to 250 x 250. Using the Fill and Crop mode keeps the aspect ratio correct.
3) The second step I added changes the file format to JPG. The default output of the first step seems to be TIFF. I tried putting ‘.jpg’ at the end, but the result of the capture was a TIFF file. TIFF being an uncompressed file format is not going to be as compact in your database. I was able to drop the file size from 190 kb to 19 kb, one tenth of the size by using these two additional steps, so it is probably worth adding some kind of additional processing at this point to preserve space if image quality is not paramount.
The Demo file – How it works
When you first launch the demo, download the Automator routine to your computer.
- Click on the ‘Take Photo with Automator’ icon. This should prompt you to download and save the Automator routine to your computer. It could be on the Desktop, in your Documents folder, or even in you FileMaker Extensions folder.
- Make sure you unzip the file if it doesn’t automatically do so.
- Next, click the Insert Picture from Webcam button.
First Run Error
If you see this screen, you forgot to unzip the downloaded application. You will need to unzip the Automator application and restart FileMaker Pro to get it working correctly. Once the Automator file is unzipped, the Insert Photo from Webcam script should work.
Automator’s camera prompt
If everything is working correctly, you should see a camera countdown and the screen will flash as it takes your photo.
If you have any problems with the downloaded version of the Automator routine, make sure that you are running on a Macintosh with OS X, the Automator app has been downloaded AND unzipped somewhere on your computer. If you are seeing error messages, relaunch FileMaker and try the Import button again.
To edit the file in Automator, launch Automator use the File Open command to get access to the steps in the app. Try recreating the steps above or customizing them to your needs. If you change the name of the Automator routine, make sure you update the references in Applescripts that FileMaker Pro calls. Automator uses Apple Events to call the App and if it doesn’t show up in the list of Applications, the routine may choke.
The Scripts that Matter
This file is a modified Contact Management file from FileMaker’s built-in Templates. There are only two important scripts in a folder appropriately named ‘These Scripts Matter’.
‘Insert Picture from Webcam Using Automator’ script.
Insert Picture from Webcam Using Automator
#Test for Macintosh
If [ Abs(Get ( SystemPlatform ))=1 ]
#Delete any files that may be hanging around, so you can be sure you are importing the right one.
Perform AppleScript [ Native AppleScript: tell application “Finder” delete (every file of desktop whose name begins with “FM-WebCam-Snapshot”) end tell]
#Call the Automator App to take a photo.
Perform AppleScript [ Native AppleScript: tell application “Take Photo With Automator.app” activate end tell ]
#Set the path to the desktop.
Set Variable [ $FilePath; Value:Get ( DesktopPath ) ]
#Name the file. This should be the same name that the Automator.app script is running.
Set Variable [ $FileName; Value:”FM-WebCam-Snapshot.jpg” ]
Set Variable [ $FullPath; Value:$FilePath & $FileName ]
#Set a $StartTime for the timeout code.
Set Variable [ $StartTime; Value:Get ( CurrentTime ) ]
#Check for photo on desktop every 2 seconds, import the photo once AppleScript doesn’t return an error trying to alias the file.
Set Error Capture [ On ]
Pause/Resume Script [ Duration (seconds): 1 ]
Go to Field [ Contact Management::Image_Data ]
Insert Picture [ “imagemac:$FullPath” ]
ExitLoopIf[Get(LastError) ≠ 100]
#Timeout after 20 seconds of waiting and trying.
If [ Get(CurrentTime) > $StartTime + 20 ]
Show Custom Dialog [ Title: “Timeout”; Message: “Oops, we were unable to find the picture on the desktop after waiting for 20 seconds. Sorry.”; Buttons: “OK”]
Exit Loop If [ 1 ]
Set Error Capture [ Off ]
#Import the photo into a FileMaker field.
Go to Field [ Contact Management::Image_Data ]
Insert Picture [ “image:$FilePath/$FileName” ]
#Clean up: Delete the photo from your desktop.
Perform AppleScript [ Native AppleScript: tell application “Finder” delete (every file of desktop whose name begins with “FM-WebCam-Snapshot”) end tell ]
Show Custom Dialog [ Title: “I got nothing for you.”; Message: “This application because it uses AppleScript, only runs on a Macintosh.”; Buttons: “Do’h” ]
Notes: If you change the name of the Automator app, please update the references in the Perform AppleScript steps. Thanks to Rob Alder for improving this script for me.
Dealing with a USB Camera that is NOT a built-in iSight
In the end, the Automator approach didn’t work in my solution. Things all worked fine on my development machine. In my office, I use a MacBook Pro setup in a Henge Dock (I love it, thanks for asking). This means that the MacBook’s lid is closed and the computer is plugged into an external monitor, so the iSight camera is blocked. For Skype calls etc, I use a Logitech HD camera. Fortunately, the Automator routine was smart enough to figure out that the iSight was offline and defaulted to using the Logitech camera.
When I ran the Automator app with my client’s system, things did not go so smoothly. In the gym, they have an iMac facing the staff and a USB camera plugged into it facing the customers. I needed the Automator routine to run using the outward facing USB camera. The Automator routine was getting confused because there are two cameras running, the built-in iSight and a separate USB webcam. Of course it defaulted to the iSight and there is no configuration Control Panel to tell it different. (Where is the Camera control panel Apple? There is one for Audio, how about a Video control panel?) In order to disable the iSight camera I found a set of Terminal commands to remove the iSight drivers, so that the Automator routine would default to the USB webcam instead. Sadly, the Dynex USB camera didn’t show up as when the iSight went offline.
I went searching for another solution and found an inexpensive ($12.95) AppleScript-able webcam app with a very simple interface called CamSpinner. The structure of the script is very similar. I had to setup CamSpinner’s preferences, select the USB webcam as the default camera and set a default file name for when it takes a photo. The major difference is the AppleScript call to CamSpinner looks like this:
tell application “CamSpinner”
set theFile to grab
tell application “Finder”
set the name of (every file of desktop whose name contains “PTSnapshot”) to “PassTracker Snapshot.jpg”