Scripting import of media into FileMaker Pro container fields
Scripting import of media into FileMaker Pro container fields
- Subject: Scripting import of media into FileMaker Pro container fields
- From: Larry Bartram <email@hidden>
- Date: Thu, 21 Jun 2001 08:28:18 -0400
Scripters all:
Here's an AppleScript scripting challenge that has been killing me. I've
worked on and off for almost 6 months on this with no success. Any help
would be appreciated immensely.
The script should import of a folder of images into FileMaker Pro container
fields. It should:
1. Create (or update, if a record of that name already exists) a record in a
FileMaker Pro 5 database for each media file in a folders. It should also
root through all the sub-folders in each folder.
2. Include the image file (or other QuickTime compatible media files) in a
container field in each new record, plus the file name in a file name field,
and a path in a file path field.
3. The container fields should just reference the original files, NOT import
the actual contents of the sound/picture/movie.
Here's my current state of affairs:
Once upon a time, Ehsan Saffari kindly provided his effort to my question
about importing a folder full of image files into FileMaker Pro container
fields.
Here is his script:
------------
global namelist, imagelist,thetime
on open of myFolder
set namelist to {}
set imagelist to {}
set thetime to current date
try
set theList to (list folder myFolder without invisibles)
repeat with aFile in theList
set thefilepath to (myFolder & contents of aFile) as string
set thefile to file thefilepath
set namelist to namelist & aFile
set imagelist to imagelist & thefile
end repeat
tell application "FileMaker Pro"
tell document "Templates"
repeat with x from 1 to count of items in namelist
create new record with data {item x of namelist, item x of imagelist}
end repeat
end tell
end tell
set thetime to (current date) - thetime
tell me to activate
display dialog (thetime & " seconds for " & (count of items in namelist)
&, " images") as string buttons {"OK"} default button "OK" with icon 1
on error e number x
display dialog e & " Error Number " & x
end try
set {namelist, imagelist, thetime} to {"", "", ""}
end open
------------
IMPORTANT: the two fields (namefield,imagefield) are the only fields on
the layout and inserted on the layout in that order.
---------------------------
Although I've tried using it many times, it just doesn't work. There are
several problems:
1. Syntax. There is something wrong in here with an extra comma, or
something. When I remove the comma on the line:
&, " images") as string buttons {"OK"} default button "OK" with icon 1
It compiles, but it still doesn't work.
2. I always get an out of memory error.
I've also played with the script below (from another source; I've honestly
forgotten where... To the author, my apologies.)
------------
--choose a folder with picture files
activate
set folderPath to (choose folder with prompt "Choose a folder with pictures
to import
")
--create a list of all files in the folder
set fileList to list folder folderPath without invisibles
--initialize pictureCount variable
set pictureCount to 0
--create a new record for each picture
repeat with pictureFileName in fileList
tell me to set pictureFileRef to (folderPath & pictureFileName as
string)
if folder of (info for (alias pictureFileRef)) = false then
if file type of (info for (alias pictureFileRef)) = "JPEG" then
tell application "FileMaker Pro"
activate
tell database "Picture Database"
set newRecord to create record
go to newRecord
set cell "Name" of newRecord to pictureFileName
set cell "Picture" of newRecord to file (pictureFileRef)
set pictureCount to pictureCount + 1
end tell
end tell
end if
end if
end repeat
--display number of pictures found
tell me to activate
if pictureCount = 0 then
display dialog "No files of type JPEG were found in folder " &
folderPath
else
display dialog "Number of pictures imported using file reference: " &
pictureCount
end if
---------------------------------
This script just looks for .jpg files. I modified it with an extra couple
loops in the middle to look for .tif files and .pct files, too, but this
script gets hung up all the time on files of "the wrong type", and I don't
know exactly what that means. It is also slooooooooow.
If anyone could help out here it would be a valuable education for me, for
many others on the list, and would solve a problem that seems tailor made
for scripting: the repetitive task of importing large numbers of files into
container fields in FileMaker Pro.
On the bbs.applescript.net list, there was a suggestion that perhaps "the
entries" in the Akua Sweets scripting extensions may have an answer but I'm
unfamiliar with Akua Sweets.
Thanks again for your help.
Larry Bartram