Embed picture in Filemaker

Is it possible with Applescript (or any other way) to embed an image into a database.

I have run scripts that place an image into a container,
but this is only a reference to the image.

For example:

set folderPath to choose folder
tell application “FileMaker Developer”
activate
repeat with i from 1 to count of records
tell record i
set pictureFileName to cell “Ad Number” & “.pdf” as string
try
set cell “Picture” to file (folderPath & pictureFileName as string)
end try
end tell
end repeat
end tell
activate
display dialog “Done”

There are two basic ways to embed a picture into FileMaker. The first, using just AppleScript, is to use something like the Scripting Addition “GraphicsImporter” (available here at macscripter). I can get the image from the file, in a way that can be set to FileMaker cell (container field). The only real difference in the set line is that you do NOT use the word “file,” you just set it to the variable you produced earlier wit GI’s gi convert command.

Your example, because it is PDF, leads me to mention the second method, and the reason why. It is to use AppleScript to move/rename the file to a fixed known location, then call a native FileMaker script to Insert Picture (or Insert Quicktime). By “fixed” I mean that it must be stored in the FileMaker Insert Picture script step. This is visible and editable in FileMaker 7, but not in 6. But it both cases it’s fixed.

If the FileMaker file is hosted on a network, via FileMaker sharing (the only correct way to do it), then you have a problem with the “known” requirement. There are a couple of known locations. One is the Shared folder:
In AppleScript: Macintosh HD:Users:Shared:Import.pdf (or path to “sdat” as string)
The FileMaker network path is: filemac:/Macintosh HD/Users/Shared/Import.pdf
Or the temporary items folder:
Macintosh HD:private:tmp:501:TemporaryItems:Import.pdf (path to “temp” as string)

The reason why you may want to use the second method is that directly embedding with GraphicsImporter seems to only work with the default type (don’t specify a type), which is “PICT”. So, no matter what type the file is, you end up inserting a PICT, which is quite large. In the case of PDF’s it looks good on the screen, but prints crappy; and it’s only the 1st page (pictures are always 1 page). If you specify anything else, like “JPEG” or “PNGf” (both of which are supported by GraphicsImporter) you get a FileMaker error and cannot embed. Maybe someone knows how to get around this; but I don’t.

So, the 2nd method is I think the way to go. In FileMaker you can use either Insert Picture for pictures, or Insert Quicktime. The latter will insert all the pages of a PDF document, with the “movie” controls at the bottom for moving through them.

It will only print the 1st page though. Unless someone knows some way to access those pages while in the FileMaker container field. I somehow doubt it.

You can however also use Insert File (FileMaker 7) to put the entire PDF file into a container field, as well as Insert Quicktime in another field. Then you can use Export Field Contents to export it as a file, then open it with Preview or something to print normally. So you’re storing it twice, but you can then do whatever you need to.

There is one more glitch :expressionless: FileMaker needs the extension in the Insert fixed file reference. So you need a separate reference for “.jpg”, “.pdf”, etc… I’d use a separate Insert step for each; you can branch according to the original file name’s extension. The AppleScript must also do this. It’s not a big deal, but it’s annoying.

Yes, it’s more complicated than it should be. But that’s the way it is (as far as I know). This is my AppleScript:


tell application "FileMaker Developer"
	-- the above line and its end tell would not be in a FileMaker Perform AppleScript step, or be commented out
	set shared_folder to path to "sdat" as string
	set PDF_file to shared_folder & "Import.pdf"
	set JPEG_File to shared_folder & "Import.jpg"
	set isImage to false
	
	tell application "Finder"
		set FileRef to (choose file with prompt "Choose the PDF or JPEG file to Insert.")
		set FileInfo to (info for FileRef)
		set fileType to file type of FileInfo
		set FileName_ to name of FileInfo
		set ext to name extension of FileInfo
		
		set movedFile to duplicate file FileRef to folder shared_folder with replacing
		-- replacing should not be needed
		
		if exists file PDF_file then
			delete file PDF_file
		end if
		if exists file JPEG_File then
			delete file JPEG_File
		end if
		-- delete the "Import.pdf" or ".jpg" file, so we can rename w/out error
		
		if ext is "pdf" then
			set isImage to true
			set name of movedFile to "Import.pdf"
		else
			if ext is "jpg" then
				set isImage to true
				set name of movedFile to "Import.jpg"
			end if
		end if
		
	end tell
	
	activate
	
	if isImage is true then
		tell current record of layout "AS" of window 1
			set cell "FileName_" to FileName_
		end tell
		tell window 1
			do script FileMaker script "Insert File"
		end tell
	end if
	
end tell

And the FileMaker 7 script (could be modified for 6, but the Insert references would be hidden, and the Else If step would have to be Else, then If, with another End If:

Do NOT Rename script. Called by AppleScript.

Go to Layout [ “AS” (ImagesPDFs) ]
Commit Records/Requests
Go to Field [ ImagesPDFs::FileImage ]
If [ Right ( ImagesPDFs::FileName_; 3 ) = “pdf” ]
Insert Picture [ “imagemac:/Macintosh HD/Users/Shared/Import.pdf” ]
Commit Records/Requests [ No dialog ]
Insert File [ ImagesPDFs::File_; “filemac:/Macintosh HD/Users/Shared/Import.pdf” ]
Else If [ Right ( ImagesPDFs::FileName_; 3 ) = “jpg” ]
Insert Picture [ “imagemac:/Macintosh HD/Users/Shared/Import.jpg” ]
End If Commit Records/Requests [ No dialog ]
Go to Layout [ “pdf_Layout” (ImagesPDFs) ]