tell application "Address Book" to set _img to image of person "John Doe"
tell application "FileMaker Pro" to set cell "photo" of current record of layout "LAYOUT_NAME" of database "DATABASE_NAME" to _img
In Script Debugger 4 the var _img displays the picture in the sidebar of the script’s window. The script executes without errors, but:
In FileMaker Pro the cell contains this text only: “Unknown container object”.
Does anyone know how to parse the picture’s data (it’s shown as TIFF) into the database so it shows the pict?
If you want to have the picture embedded in the container cell, then you must convert the Address Book picture format which registers on the clipboard as NeXT v4.0 pasteboard type to Apple PICT pasteboard type for to be able to pass the clipboard through Applescript. A call method command to the right Obj-C methods should make it, but that’s beyond my knowledge level. You must pass the image through the clipboard anyway for to make it work.
Until then, there are 2 solutions among others probably.
Instead of storing content in the container fields in FileMaker, to store file references to existing files. So, you can have an images folder that always ‘follows’ your DB file.
property db_pics : "Tristan:tests:"-- change to your folder that will contain the files
tell application "Address Book" to tell (item 1 of (get selection))
set {img, lName} to {image as TIFF picture, last name as Unicode text}
--personaly I prefere to use nickname to distinguish dupplicates,
--but not everyone uses that property
end tell
tell me to set the clipboard to img
set f to (("" as Unicode text) & db_pics & lName & ".tif")
set w to open for access f with write permission
try
set eof w to 0
write img to w as TIFF picture
close access w
on error e number n
close access w
end try
tell application "FileMaker Pro" to set cell "photo" of current record of current layout to file f
A workaround that embeds the data to the FM cell but does NOT work with all kind of images – i.e. it works with pictures stored in Address Book that originally were saved as TIFF image from Adobe Photoshop, but not from Preview – is the following
a.) Create a FMPro script in your DB file that shows under the Scripts menu (in this example it’s the only one so it has direct access with command+1
Set Selection [test:photo] # modify as needed
Cut Select
Perform Applescript [“delay 0.2”] # this is optional
Paste Select
By doing so you convert/addType of the picture stored as a reference to the file, which registers on the clipboard as ('FPth CorePasteboardFlavorType <memory address.) to content (Apple PICT pasteboard type). You could do the copy paste with Applescript but it’s better to do it within FM.
b.) the script
tell application "Address Book" to tell (item 1 of (get selection))
set {img, lName} to {image as TIFF picture, last name as Unicode text}
end tell
tell me to set the clipboard to img
set f to ("" & (path to "temp" from user domain) & "temp_file") & lName & ".tif"
set w to open for access f with write permission
try
set eof w to 0
write img to w as TIFF picture
close access w
on error e number n
close access w
end try
tell application "FileMaker Pro"
activate
set cell "photo" of current record of current layout to file f
tell application "System Events" to tell process "FileMaker Pro"
keystroke "1" using command down
end tell
end tell
So, Thomas, by using the above oxax, to what you want that would be
tell application "Address Book" to tell (item 1 of (get selection)) to set img to image as TIFF picture
tell me to set the clipboard to (giconvert (giconvert img type "TIFF") type "PICT")
tell application "FileMaker Pro" to set cell "photo" of current record of current layout to (the clipboard)
You do not have to use the clipboard. It works like a charme silently in the background:
tell application "Address Book" to set _img to (image of person "John Doe") as TIFF picture
tell me to set _img to (giconvert (giconvert _img type "TIFF") type "PICT")
tell application "FileMaker Pro" to set cell "CELL_NAME" of current record of layout "LAYOUTNAME" of database "DATABASE_NAME" to _img