Getting the Correct Path for a Picture in a Container Field When Only a Reference to the File Has Been Stored

You can place the references (pathnames) of a picture container field into another field using AppleScript.

This information was provided by Claris Corporation on 16 March 1998, and incorporated into Apple Computer's Tech Info Library.

Container fields in FileMaker Pro 3.0 can store a reference to a graphic file instead of storing the actual graphic within the database. By importing a picture and storing a reference only, you can display the graphic on your layout while it is actually stored elsewhere. FileMaker Pro stores the path and name of your file in the field, but there is no feature which allows you to view or modify this path directly. This may become a issue if, after importing pictures as a reference only, you decide to move them to another folder, or if you are using a Web publishing tool that needs to access the references to those pictures so they will appear on a Web page.

AppleScript to the rescue!
A solution to this issue lies in the use of AppleScript applications. The two AppleScript applications below can be used to manipulate the references stored in container fields. They are provided as a reference only and can be modified to more precisely fit your needs. For example, you may alter these AppleScript applications to direct another application to open the graphic instead of putting the reference into a FileMaker Pro field. Or you can use the Replace command to change parts of the path name field to reflect a relocation of folders and then run the script to update or "mass re-import" graphics as references.

Both AppleScript applications were written based on the following assumptions:

1. All records in the current found set contain graphics that have been imported using a reference.

2. The relevant container field is named "Picture."

3. The text field to contain the reference/path is named "FileName."

4. The scripts are to be run as separate applications, either executed manually or by using the "Send Apple Event" script step in ScriptMaker software.

5. FileMaker Pro has the relevant database open and is currently the foremost, or foreground application.

6.You have made a backup of your databases before running these AppleScript applications.

The following AppleScript named "Get References" will get the path name and put it into the field "FileName."

Tell application "FileMaker Pro"
-- count the found set of records in the (current) database and
-- put that number into NumOfRecords.

set NumOfRecords to count record of layout 0 of database 1

-- Loop through all the found set

repeat with i from 1 to NumOfRecords

-- Get the contents of "Picture" in a certain record of the
current database

set PictureReference to cell "Picture" of record i of layout 0
of database 1

-- Put the contents into "FileName" as text

set cell "FileName" of record i of layout 0 of database 1 to
PictureReference as text

-- Stop when you run out of records

end repeat
end tell

The following AppleScript named "Set References" will use the path name in the "FileName" field update the reference in the a field "Picture."

tell application "FileMaker Pro"

-- count the found set of records in the (current) database and put that number into NumOfRecords.

set NumOfRecords to count record of layout 0 of database 1

-- Loop through all the found set

repeat with i from 1 to NumOfRecords

-- Set the data reference of "Picture" to the file whose name
is "FileName"

set data of cell "Picture" of record i of layout 0 of database
1 to file (cell "FileName" of record i of layout 0 of database
1 as text)

-- Stop when you run out of records

end repeat
end tell
Published Date: Feb 18, 2012