Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript works fine in ScriptEditor but not in Filemaker Pro

I'm getting an odd result from an Applescript script being called from within Filemaker that I've not seen before nor have I found a reference to it online here or elsewhere.

The following script creates three new records and makes a call to the Filemaker script "paste_into_container". The FM script "paste_into_container is very simple, it pastes whatever is currently on the clipboard into a specific container field. When the script is called from within Filemaker, the "paste_into"container" subscript will only paste the contents of the clipboard into the last new record. The container field on the first two records is left blank.

It's almost as if the loop creates the new record, ignores the "go to last record and "paste_into_container" lines in the script, and then moves on to the next iteration of the loop.

The script works fine when called from ScriptEditor but fails when called from within Filemaker. The script will also work if I drop the repeat loop and create just one record.

I've tried increasing the delay added at the end of each loop but it does not make any difference whether it is 1 or 15 seconds.

I'm sure it's something simple but I'm not seeing it and after two days it's time for help (of one kind or another)

additional info:

Mac OS 10.6.8

Filmaker Pro 11 running with Filemaker Server 11

Thanks in advance

Phil

tell application "FileMaker Pro"
    show every record in table "Image_Info" in database myDB
    go to layout 1 of database myDB
    repeat with i from 1 to 3
        set myNewRecord to create new record in database myDB
        go to last record
        do script "paste_into_container"

delay 1

    end repeat
end tell

Intel iMac7, Mac OS X (10.5.8)

Posted on Oct 23, 2012 2:12 PM

Reply
8 replies

Oct 25, 2012 11:54 AM in response to philc_transcon

Hi...there's a very good discussion on another forum specifically about this problem. When FM moved from FM10 to FM11 they changed how they are handling requests from imbedded applescripts. Essentially, since FM11 Filemaker treats Applescript commands asynchronously rather than synchoronously whenever the Applescript calls on an internal Filemaker script with the do script command. What this means is that Filemaker will allow the Applescript to continue without waiting for feedback from Filemaker saying the internal FM script is complete. There is a work around but it is hardly elegant. See link below.


As I understand it this only affects embedded Applescripts calling on other local Filemaker scripts.


http://forums.filemaker.com/posts/4b2544f7a4?page=2

Oct 25, 2012 1:36 PM in response to philc_transcon

well, if that's the problem you could try using a considering application responses block. note that I don't have FileMaker so I can't test it, and I'm not at all positive it would work anyway, but it's worth a try.


tell application "FileMaker Pro"

show every record in table "Image_Info" in database myDB

go to layout 1 of database myDB

repeat with i from 1 to 3

set myNewRecord to create new record in database myDB

go to last record

considering application responses

do script "paste_into_container"

end considering

delay 1

end repeat

end tell

Oct 26, 2012 4:15 PM in response to twtwtw

Hi TW


Good suggestion. I tried it but no result.


Here's what's odd. I created two fields in the FM database, one called ScriptCall and the other ScriptResult. I then modified the applescript as follows:


tell application "FileMaker Pro"

show every record in table "Image_Info" in database myDB

go to layout 1 of database myDB

repeat with i from 1 to 3

set myNewRecord to create new record in database myDB

go to last record

set cell "ScriptCall" in myNewRecord to "1"

considering application responses

do script "paste_into_container"

end considering

set cell "ScriptResult" in myNewRecord to "1"

delay 1

end repeat

end tell




I set this up to test where the problem might be. The results were odd. The applescript creates three new records.


Record 1

ScriptCall = 0

ScriptResult = 0


Record 2

ScriptCall = 0

ScriptResult = 0


Record 3

ScriptCall = 1

ScriptResult = 1

Oct 26, 2012 5:15 PM in response to philc_transcon

well, as I said, I don't have filemaker to play with. At a guess... FM is likely returning references to cells rather than working directly with values, and references can be a little hairy when you reuse variables. try saying 'set contents of cell "ScriptCall"...' or maybe use value instead of contents. The aim would be to dereference the variable and force an immediate change in value. If that throws an error my guess about it being a reference might be wrong, or FM might have its own nomenclature for doing that.


Also, does the script "paste_into_container" return anything, or does it spin off subprocesses? Applescript is probably smart enough to recognize that there won't be a return value and ignore the considering clause. try returning a boolean value at the very end of the shell script (and use 'set dummy to do script ...' to catch that dummy value), see if that changes anything.

Oct 26, 2012 5:34 PM in response to twtwtw

I've solved the problem with the ScriptCall and ScriptResult. So now everytime a new record is created in the loop ScriptCall =1 and ScriptResult = 1


No text is pasted into the clipboard.


The paste into container script only has the paste command and a exit script command. It does not spin off any subprocesses.


If I remove the repeat loop from the applescript the paste into container command works fine. It is only when it occurs inside a repeat loop that either Applescript skips over it or Filemaker does not call the command until the last loop.

Oct 29, 2012 8:15 AM in response to twtwtw

The other odd item is that Filemaker does not respond to the command to go to the last record after the new record is being created. It stays at the current record until the loop has completed.


Ideally I would not use the paste into container script at all but I'm stuck with it as there are limited means of entering information into a container field via Filemaker scripts. The script that I showed here is a proxy. The actual script opens an image file in Photoshop, resizes it to 100x100x72 and then copies the image into the container as a thumbnail image. It's an legacy solution that i have to maintain for now.

Applescript works fine in ScriptEditor but not in Filemaker Pro

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.