Re: Import a picture into FileMaker without osax
Re: Import a picture into FileMaker without osax
- Subject: Re: Import a picture into FileMaker without osax
- From: Steven Angier <email@hidden>
- Date: Sat, 22 Sep 2001 11:18:00 +1000
- Organization: Macscript.com
Jean-Marie Hoornaert wrote:
>
With this script, and with the example script provide with de application,
>
you can only import "a reference to" the picture.
>
If the original picture is delete, then, FileMaker don't display this
>
picture yet.
My mistake. I read your original post too quickly.
There is a way to do what you want, but you're not going to like it :-)
This method involves pre-defining a FileMaker import script in your solution.
If this is not possible for some reason, then you are out of luck.
Here is an overview:
1. create an alias to the file you wish to import in a temp folder and give
it a constant name
2. tell FileMaker Pro to go to the cell of the record in which you want to
import the picture
3. tell FileMaker Pro to perform its import script
To set this up:
1. create a temporary directory (e.g. "Macintosh HD:temp folder:") and copy
any image into it and rename it to something like "tempfile"
2. create a FileMaker script in your database (call it "Import Picture")
with a single script step: "Import Picture" and point the import at the
temporary file from step 1
You can use the code below to help you. It makes alias files and does the
importing.
A few notes about scripting FileMaker Pro in general:
1. FileMaker Pro is extremely slow at responding to AppleEvents: when
FileMaker is in the front, it will respond to approximately 1 event per second
(on any hardware). This is because FileMaker gives most of its processing time
to waiting for GUI events. When FileMaker is NOT in front (hidden or not), it
responds to approximately 6 events per second (again, on any hardware).
Because FileMaker is not in the front, it does not waste time on waiting for
GUI events.
The point of this is: when sending general queries/commands to FileMaker,
make sure that it is NOT in front.
2. FileMaker Pro is incapable of running a FileMaker script unless it is
the front application, so be sure to activate it first before calling the "do
script" command.
3. No matter what FileMaker file you tell to perform a FileMaker script,
FileMaker ALWAYS tries to get the front file to execute a script of the given
name. Be sure to test that the front document is the one you want to target or
use the "go to" command to get FileMaker to bring that document to the front.
Having said that, it is sometimes possible that the frontmost file is
invisible (because it is hidden) and while the one you want to target looks
like it is in front, it actually is not. Unfortunately in such circumstances,
the "go to" command is of no help because it will not put the front visible
document in front of the front hidden document.
4. Try to avoid using "Perform AppleScript" to run and/or trigger something
in an external AppleScript application. Perform AppleScript will ALWAYS wait
for a formal AE reply (for 60 seconds I think). When it doesn't get one, it
generates an error in your FileMaker script. Instead you should use "Send
AppleEvent" which also allows you to supply a field value. Create custom
events in the target application and call them from the "Send AppleEvent"
command.
Hope this helps,
Steven Angier
Macscript.com
----
--store path to your temporary folder (where FMP will look)
set theTempPath to alias "Macintosh HD:temp folder:"
--store name of the alias file (which FMP will look for)
set theTempFileName to "tempfile"
--store path to the image to import
set theImageFile to "Macintosh HD:folder 1:somefile.gif"
--build a path to the prospective alias file (to test its existence)
set theAliasFile to (theTempPath as text) & theTempFileName
tell application "Finder"
--delete any leftover alias file
if exists file theAliasFile then delete file theAliasFile
--make an alias to the image file in the temp folder
make alias at theTempPath to file theImageFile ,
with properties {name:theTempFileName}
end tell
--now that the image we want to import has been "aliased",
--we can tell FileMaker to perform its import script
tell application "FileMaker Pro"
tell document 1
--go to the target cell of the target record
go to cell "Picture" of record 1
--call the FileMaker script to import the fixed picture file
--note: FileMaker must be in the front when perform a FM script
activate
do script "Import Picture"
end tell
end tell
----