How to execute AppleScript Sub-Routine from FileMaker

I am trying to utilize the function listed in FileMaker 7.0 help. It states:
Use Perform AppleScript to communicate with applets and other scriptable applications. For example, if you have created an AppleScript applet with sub-routines, you can call the handlers using the Perform AppleScript command like this: Perform AppleScript (“tell application “My Applet” to doMyRoutine()”)

I have created an AppleScript with a basic file write routine. The script has the basic format of:
on myroutine(opt1,opt2,opt3)
code
end myroutine

I used the format provided by FileMaker help to call this routine. It will, however, not work (it fails with a “Connection is invalid” error). I have actually tried this with a couple of routines and none of them work. Basically what I want to do is to be able to pass the contents of one or more fields from a FileMaker script to an AppleScript routine which will write content to a file. I cannot find any further information from FileMaker on what is required to make this work.

I have even tried to make the whole of the script perform as a calculated script in FileMaker as well with no success. I can’t figure out what you have to do to make it like multiple lines.

It seems like this should be simple, given the information in the help, but for the life of me can’t get it to work. Any help on how to make this work will be greatly appreciated.[/i]

Hello,

If you are trying to extract data in your external script you require something like this:

tell application “FileMaker Pro”
set myvariable to cell “fieldinfilemaker” of current record
end tell

If you are trying to insert data from your external script you require something like this:

tell application “FileMaker Pro”
set cell “fieldinfilemaker” of current record to myvariable as string
end tell

you can also run filemaker scripts from your external applescript with:

tell application “FileMaker Pro”
do script “what ever”
end tell

let me know if you need more

andy

Hi Andy, thanks for responding. What I am trying to do is to pass a value to an AppleScript and have AppleScript perform a function using that value. Basically, I have a FileMaker script which walks through a set of records and gets a value from a related table. I want to then pass that value to an external AppleScript. This AppleScript will take the data, format it, and output it to a file. Or at least that is the plan. I have an “On x” handler in the AppleScript, but it doesn’t like the parameter. I was using an example in the help for the FileMaker side, but I can’t find an example on the actual AppleScript.

I am not married to the AppleScript, but that seemed to be the easiest way to accomplish what I was trying to do. What I want to do be able to do is to go through each selected record on a FileMaker form, read several fields from the top row in a related table, format those fields and output to a text file (one line for each record). With the FileMaker script, I have everything done except for the writing the line to the file. I could probably do the whole thing in AppleScript, but it would be a lot easier if I could just pass the desired string to the AppleScript which can write the text file. This would also be a re-usable function that I could do other stuff with.

Does that explain better?
Bill

I am primarily a FileMaker developer, who also does some AppleScript; so that’s my bias. This process could be done either mostly with FileMaker, with a little help from AppleScript, or visa versa. If you’re not particularly expert with either, it may be easier to start with FileMaker.

Exporting certain fields from a FileMaker file’s records, including fields from the 1st matching record of a related file (or table in version 7) to a text file is all easily doable. You just export them, as text, to a specified name and location.*

It exports the current found set of records, each to its own line. Such an export can be saved, to be reused, with the Export script step (in v.6), after a successful export. The fields and order can explicitly specified in the step in version 7, so no previous export is needed.

AppleScript would be used to rename, and optionally move the exported file elsewhere. Because a saved FileMaker export is always to the same fixed file name and location, overwriting without dialog any previous file. You can use a field in the database for the new name.

The rename/move would be run in a Perform AppleScript script step in FileMaker. You can paste an AppleScript in there and run it from FileMaker (after writing it in Script Editor, FileMaker has no coloring or other niceties, it just runs it well). Much faster than an AppleScript app. It’s best to remove or comment out the "tell app “Filemaker Pro” lines inside FileMaker (except nested ones); it knows who it is.

*On networked files you cannot specify the location for client machines in a script; but the default is the FileMaker application’s folder, which is easy enough to find with AppleScript.

We can’t post files here, but if you go to http://www.fmforums.com/ there is an AppleScript section, and someone (maybe me :slight_smile: can help with an example.

Hi Bill!

Please le me introduce myself: I am a small business owner in Brazil and do some AppleScript programing for pleasure, and for my own use.

By reading your text, I believe I had once the same problem as you and found a solution that other more experienced programmers might have done in a simpler of more geeky way.

My Filemaker Database I use to control my sales, money I have to receive from people, printing invoices, and this database interacts with other databases, like clients, transporting companies (that have to appear on the invoice), products, etc… etc…

Invoices in Brazil have to be Matrix-dot printed using specially controlled forms. So my invoices only had text, without titles. The titles come already printed in the forms.

In the main database I use to interact with the other databases I created a layout that would compile what I call “a balance of your purchase”, I would print it to PDF and email my clients reminding them of their debts.

So far so good. But many of my clients, mostly Pc users, would say “can’t open the attachment”, simply because they didn’t have Acrobat Reader installed.

Dam Windows that looks more like a car that doesn’t come with seats or wheels!

So I started to work on a way to send the balance document on an “html enclosed” email, I mean an email with text, pictures, and links.

Question: How to get the data out of my “Filemaker database”?

I have aprox 100 fields of data. But I only needed some 30 fields to assemble my dinamic email.

Solution:

I created a blank layout on filemaker and added the fields I needed. Instructed filemaker to gotolayout > select all field > copy > do applescript do shell script “open /path to my applet”

My applet collects the data from the clipboard as a text, each field is separated by a tab character, a default feature of Filemaker.

By refering to the items as a list I build my dinamic email and have PostFix enabled to send the email.

The first solution I had was originally just an Applet. But my last build was done in Applescript Studio that shows me the email on a webView, before trigerring the email itself.

I hope I can help you by explaining you my solution.

Bernardo Höhl

Rio de Janeiro - Brazil