Recently a client requested we capture webpages for them. As a marketing company recording evidence of the exposure they gained their clients is key requirement. They had for many years manually stitched screenshots together. While cheap this approach was incredibly time consuming, tedious and prone to mistakes.
Luckily the client were on OS X so I was able to use webkit2png. This funky little command line utility uses webkit to render an entire webpage. Really quite handy and very simple to use. The only other difficulty is getting FileMaker to run a command line script. Applescript is our saviour here. A calculated Applescript allows us to dynamically generate the command line.
Here is the FileMaker script:
[ $$kp_screengrab; Value:SCREENGRAB::__kp_ScreenGrab ]
[ $url; Value:Get(ScriptParamater) ]
[ Calculated AppleScript:
“tell application \”Finder\”¶ do shell script \
-F -o “& SCREENGRAB::__kp_ScreenGrab & ” -D ” &
Right(Get ( TemporaryPath ); 1 + Length(Get( TemporaryPath )) – Position ( Get ( TemporaryPath ) ; “/” ; 1 ; 2 )) & ” ” & $url & “\”¶
[ $file; Value:”image:”&Get ( TemporaryPath ) & $$kp_screengrab & “-full.png” ] Go to Field [SCREENGRAB::d_ScreenGrab ]
[ “$file” ]
From the top we set a variable equal to the primary key of the record we are going to insert. This is used in the generation of the filename. We also set a variable to the ScriptParameter; this is used to pass teh URL into the script.
The perform applescript step uses the terminal to create a python command. The python command calls the webkit2png with various switches, the path to write the file and the URL. The switches are documented by typing ‘python /path/to/webkit2png –help’ in terminal. This has the added advantage of ensuring you have the path correct.
All in all a pretty easy bit of code once the R&D has been done. The biggest thing to take away is how easy it is for FileMaker to interact with the command line and command line utilities.