Flipping in FileMaker

Rotating Images or PDFs in Containers with Applescript (Mac)

In my previous blog post I talked about automating scanner documents into FileMaker container fields using AppleScript. This was based on a customer request. Logging in to that system recently, I noticed that it was fairly common for staff members to scan documents in upside down. A web search found me an AppleScript to flip PDFs and Images using the Image Events utility, which is included in most modern OS X installs. From this, I made a FileMaker Pro script for images and PDFs. I made it work with both PDFs and images because I also noticed sometimes jpegs and png files were ending up in the container (rather than just the specified PDFs).

Download Demo

This is an updated version of the demo for the original blog post.

Flipping in FileMaker

The script

Script steps

  • Set Variable [$Path; Value:Get(TemporaryPath)]
  • Set Variable [$FileEnding; Value:Right ( Documents::Name ; 4 )]
  • If [
    • $FileEnding = “.pdf” or  
    • $FileEnding = “.jpg” or  
    • $FileEnding = “.png” or  
    • $FileEnding = “.tif” or  
    • $FileEnding = “.gif”]
  • Set Variable [$FileName; Value:Get(UUID)&$FileEnding]
  • Set Variable [$FilePath; Value:$Path&$FileName]
  • Export Field Contents [Documents::Document; “$FilePath”]
  • Pause/Resume Script [Duration (seconds): 2]
  • Set Variable [$ModFilePath; Value:
    • Middle ( $FilePath ; Position ( $FilePath ; “/” ; 0 ; 2 ) ; Length($FilePath) )]
  • Perform AppleScript
    • [“set theFile to \””&$ModFilePath&”\”¶
    • tell application \”Image Events\”¶
      • set thisImage to open theFile¶
      • rotate thisImage to angle 180¶
      • save thisImage¶
    • end tell”]
  • Insert File [Insert; Display content; Never compress; Documents::Document; “$FilePath”]
  • Else
  • Show Custom Dialog [“File Name Problem”;
    • “This script can only handle files ending in ‘.jpg’, ‘.png’, ‘.tif’, ‘.gif’ ‘.pdf’.”]
  • End If

2015-06-02 Update: Cross Platform Flipping

Thanks to reader Tim Ballering, (see comments below) for the idea of a more cross-platform approach to image flipping. Important note, turn off ‘Interactive Content’ in the container field in order for the PDF (one page only) to display correctly. The demo file has been updated to include this additional approach.
 Cross_Platform_Flipping_1 Cross_Platform_Flipping_2

6 Responses to “Flipping in FileMaker”

  1. We do this by “cheating”… Using 4 overlapping calculated container fields, rotated in the 4 orientations, and a set orientation field to select which view is active. It handles any image file and works fine for our purpose.

    This was set up years ago. If I were to do it today I would just use four rotated copies of the container field and the orientation field with a hide object calc to select which was visible.

    • Hi Tim,

      I might be missing something, I could not get this to work for me. When I created a repeating field and rotated it using FileMaker’s Rotate command, and then put both container repetitions on the same layout, they both display the image in the same orientation. Is it possible that the reason your original approach works, is because you are actually storing four different copies of the file, (one in each of the repeating container fields)? If so, this increases the file storage requirement and it would seem that you would still need a method of actually flipping the image before importing a version into each of the repeating fields.

      Just tested your second idea, using a single rotated container field with ‘Hide Object When’ conditions applied, but again, it does not seem to work. FileMaker just displays the rotated container with the same orientation as the original.

      It would be cool if this worked. It would be a cross-platform FileMaker native solution without the need for AppleScript. If you can give me more details on how it works for you, I can add it to the demo file.


  2. Also demo has two records. One PNG, one PDF. For production you need to add a calc to the orientation so that it properly labels portrait pdfs as normal due to the way FMP handles them.

    • ahhh…I see the difference, I had the container field set to Interactive content. As soon as I turned that off, your technique worked. Brilliant. I will add it to the demo. Thanks Tim.

%d bloggers like this: