Macintosh OS X has a built-in command line utility for taking screen captures. This utility can be called via AppleScript. FileMaker Pro can send out this command from a script. Why would you want to take screen captures using FileMaker Pro? I can think of two good reasons: building documentation within FileMaker Pro and for tech support enquiries from users of your solutions.
Apologies to Windows developers, I looked a bit, but couldn’t see an easy way to translate this into Windows. There are a number of command line utilities available, but I didn’t see a built-in one that I could harness. With a little imagination, you can probably make your favorite utility using the model employed here.
Basic Help files database
I built a simple database (Download FM-Screen-Capture.zip) consisting of two tables, Lessons and Lesson Steps. This is a very simplified version of the documentation software ScreenSteps. ScreenSteps has many more features, including the ability to markup screenshots with arrows, boxes, text, blurs etc. ScreenSteps is well worth a look for any FileMaker Pro developers who are serious about supporting their users. Sometimes, a developer just needs to have some simple documentation within their FileMaker Pro solution and the ability to do some quick screen grabs of their software is useful.
The Lesson Steps view
Screen captured in Lesson Step view
Screen captured into container field.
The script for Grabbing a Screenshot with screencapture
A Google search brought up this Macworld Hint article from 2003, which details how to use Macintosh OS X’s built-in screencapture utility via AppleScript. FileMaker Pro of course can run Applescripts from its own scripts.
This is a two-step script:
- perform a simple AppleScript to call screencapture do shell script “screencapture -i -c”
- paste the clipboard result into a container field.
Setting the options for capturing screenshots
There are a few options with the screencapture utility.
-i sets the cursor to interactive mode, basically a set of crosshairs that the user can click and drag over a screen to capture just a portion of the screen. If instead, the desire is to capture full windows each time, employ the -w option. -c sends the screen capture to the clipboard. Once in the clipboard, the next FileMaker Pro script step is to paste the contents of the clipboard into a container field.
Perform AppleScript [ Native AppleScript:
— -i sets the cursor to ‘interactive mode’ and -c sends the screen capture to the clipboard. do shell script “screencapture -i -c”]
Paste [ Lesson_Steps::Step Image ] [ Select ]
Using screen captures in conjunction with User Help inquiries
This slightly longer script will capture a screenshot of the users entire screen and email it to a specified admin account. This script might be used in conjunction with generating a help inquiry to a system administrator. By generating an email via E-mail Client, with the ‘Perform without dialog’ option turned off, the user can see what is being sent and add any comments to the query.
The Help Screen Capture script
#Clear out script global fields.
Set Field [ Lessons::Help Notes Field; "" ]
Set Field [ Lessons::Help Screenshot Holder; "" ]
#Query the user for input about his issue.
Show Custom Dialog [ Title: “Help Request”; Message: “This script will take a screenshot of your entire screen and paste it into a Help request email. The screenshot will help your tech support person identify your issue. Please enter a description of your issue in the Notes field below. “; Buttons: “OK”, “Cancel”; Input #1: Lessons::Help Notes Field, “Notes:” ]
If [ Get(LastMessageChoice)=1 ]
#Commit the record and Adjust the Window to full screen to hide other user windows that may be open.
Commit Records/Requests [ Skip data entry validation; No dialog ]
Adjust Window [ Maximize ]
#Run screenshot AppleScript.
Perform AppleScript [ Native AppleScript: — -c sends the screenshot to the clipboard, -x does it silently. do shell script “screencapture -c -x” ]
#Paste screenshot into Global Container field. Note that the container field must be on the layout for the script to work. You could also open a separate window with the field on it.
Paste [ Lessons::Help Screenshot Holder ] [ Select ]
#Export the contents of the Global container field.
Set Variable [ $TempPath; Value:Get(TemporaryPath) ]
Set Variable [ $FileName; Value:Year(Get(CurrentDate))&”-“&Month(Get(CurrentDate))&”-“&Day(Get(CurrentDate))&”-screenshot.jpg” ]
#Send the screenshot and user notes to a support person.
Export Field Contents [ Lessons::Help Screenshot Holder; “$TempPath/$FileName” ]
Send Mail [ Send via E-mail Client; To: “firstname.lastname@example.org”; Subject: $FileName; Message: Lessons::Help Notes Field; Attachment: “$TempPath/$FileName” ]
#Adjust the window back to the proper size.
Adjust Window [ Resize to Fit ]
Setting the options for screencapture
This time, the options are to send the screenshot directly to the clipboard -c and perform this task silently -x. By leaving out the options -i and -w, the entire screen is captured.
do shell script “screencapture -c -x”