2 Replies Latest reply on Aug 1, 2010 10:04 AM by FentonJones

    Several Container Queries



      Several Container Queries


      Hi all,

      I have a layout called AddPhoto in which I have two container fields for two versions of a particular image("Original_Image" - a RAW CR2 file for which just a thumbnail jpg will be referenced; and "Edited_Photo" - the edited jpg).  There is another almost identical layout called ViewPhoto, in which the fields are read-only and cannot be changed.  

      1. I am about to start importing roughly 4000 records from an excel file, and was wondering if it's possible to have the container field automatically reference a filename that is calculated based on the other fields.  The file path would basically be "/Users/username/Pictures/Year_Month_Day/Photo#.jpg" where Photo# is the filename directly from the camera.
      2. Is it possible to make the insert dialogue for a container field default to a particular folder on the HDD, because right now it defaults to /Users/username and I would prefer it to default ideally to the calculated Year_Month_Day folder or if not the Pictures folder.
      3. Once a photo is referenced in a container field, is there a way to write a script that will open the file in the default program on the computer?  In the case of the original RAW file can I modify this file to change the extension from CR2 to jpg?

      Many thanks for any help that can be offered.


        • 1. Re: Several Container Queries

          1. Yes, FileMaker can show (or Insert) a picture (or file) based using only a text path, but it must be a FileMaker syntax path.

          imagemac:/Macintosh HD/Users/fej/Pictures/DT Pictures/Nature/100-1920.jpg

          The above is a FileMaker syntax Mac absolute path. Windows would be much the same, but "imagewin" instead (and a "drive letter" syntax instead of the drive name). You can calculate the prefix using:

          Case ( Abs ( Get (SystemPlatform)) = 1; "filemac:"; "filewin:" )

          But you still have the problem of the drive name (which you generally don't have with Unix paths). There is another function, Get (SystemDrive), which returns (for me), "/Macintosh HD/". (Notice the slashes.)

          2. FileMaker uses whatever the last folder was. So once you used Insert once, it would continue to show you that folder. If you want more control, and you are on a Mac, you could use AppleScript to "choose file", then coerce the resulting path to FileMaker syntax. Because AppleScript has an explicit "default folder" option for its file/folder dialogs.

          It can return a Mac path, which can fairly easily be coerced to a FileMaker syntax path, either in AppleScript itself or after passing it to a FileMaker global field. Obviously this method requires more work, and is Mac only, but it let's you specify the default folder for the dialog.

          You'd also need to know how to use a script Variable in the Insert dialog. 

          Or, you can just do the whole thing, choose the file and set the container field all with AppleScript (in a Perform AppleScript script step).

          set defaultFolder to path to pictures folder
          set theFile to (choose file default location defaultFolder without invisibles) as file specification
          tell current record
          set cell "PictAsRef" to theFile
          end tell

          The container field must be on the current layout using this simple syntax.

          • 2. Re: Several Container Queries

            3. Using native FileMaker you can't open a "picture" easily, but you can open a "file". Since you have referenced files inserted as pictures, all you need to do is to calculate the path using "file" instead of "image" in the prefix. Which you can do with a simple Substitute().

            Let ( [
            txt = GetAsText ( Contain );
            img_path = GetValue ( txt; ValueCount (txt))
            Substitute ( img_path; "image"; "file" )

            Result is Container. If you show this on the layout, it will show as a file icon, with the name underneath (just like an inserted file). If it is enterable and you double-click it, it will open the file, using the computer's default image editor (however it decides, which is not simple).

            If it not enterable (likely), then you need a script to open the file, only 2 steps (if the calculated file container field is on the current layout):

            Go To Field [ calculated file container field; Select/perform ]
            Commit Record

            If however you want to specify which application opens it, then you could use AppleScript, which would allow you to specify the application. 

            set theFile to cell "_cFilePathMac" of current record
            tell application "Finder" to open file theFile

            You can replace "Finder" with whatever the name of the desired application. The above could be a calculation (instead of native).