Running Scripts from within FileMaker

Hi
I am running the following script from within FileMaker

global myDocument
tell application “FileMaker Pro”
if cell “DisplayAds” = “Display” then
tell application “FreeHand 10”
activate
set myDocument to make document
Set PageSize width “&Document Width&” height “&Document Length&” Units MM
end tell
else if cell “DisplayAds” = “Classified” then
tell application “FreeHand 10”
activate
set myDocument to make document
Set PageSize width “&Document Width&” height “&Document Length&” Units MM
end tell
else
choose from list {“Display”, “Classified”} with prompt “Select an Ad Type”
set cell “DisplayAds” to the result
end if
end tell

It’s set up to run directly from the “Run AppleScript” script command. The problem I’m getting is that where it says, “Set PageSize width “&Document Width&” height “&Document Length&” Units MM”, it’s not getting the file width and length from the Document Width and Document Length fields - I’m not sure on the syntax to use to get the values from the database into the script (although I can get it to work if I use a calculation field to build the script)
Any help gratefully appreciated!!

Your problem is that you’re inside a ‘tell application “Freehand 10”’ statement, meaning that all commands are directed to FreeHand, which has no concept of the structure of your database.

The solution is simple, just copy the values into AppleScript variables before you target Freehand.

Assuming you have fields in your database called ‘DocumentWidth’ and ‘DocumentHeight’, something like this should work:

tell application “FileMaker Pro”
set docWidth to cell “DocumentWidth” of current record
set docHeight to cell “Document Height” of current record

tell application “Freehand 10”
set myDocument to make new document
set pagesize width docWidth height docHeight units mm
end tell
end tell

In the opening 'tell application “FileMaker Pro” statement, you’re copying the required values into variables. You can then reuse these variables in the ‘tell application “Freehand 10”’ statement.

Note: I don’t have FreeHand 10 here, so this all depends on FreeHand supporting the ‘set pagesize’ command.

That’s brilliant thanks - I thought that was how to do it but had been putting it above the Tell FileMaker statement.

My next question is;
If AppleScript finds no value in the field AdType (which means there will no value in the cell “Document Length”) it prompts you to select one and then updates the database and adds the correct size into Document Length

else
choose from list {“Display”, “Classified”} with prompt “Select an Ad Type”
set cell “DisplayAds” to the result
tell application “FreeHand 10”
activate
set myDocument to make document
Set PageSize width docWidth height docHeight Units MM
end tell

While it updates the database and then continues with the Set PageSize in Freehand, it seems to go too fast for FileMaker and continues before the Document Length has been processed. Is there anyway to get it to pick this up/add a pause in the script for a second or two or something like that?
Thanks!!

If you’re pre-calculating the DocumentLength variable in the same was as my previous example, the script will never see the new value, no matter how long a delay you add to the script.

Consider the following:

tell application "Filemaker Pro"
  set docLength to cell "DocumentLength" of current record
  if docLength = "" -- cell is empty
    -- so set it to some value
    set cell "DocumentLength" of current record to "12345"
  end if
end tell

tell application "Freehand 10"
  set pageSize to height docLength
  ---bzzzzzzzz - 'docLength' is still empty since we recorded the value before we set the field value
...

Instead, the simplest fix is to update both the FileMaker field AND the variable at the same time:

  if docLength = "" -- cell is empty
    -- so update the database field
    set cell "DocumentLength" of current record to "12345"
    -- AND update the variable
    set docLength to 12345
  end if

-- now Freehand will get the proper docLength variable

All running fine now - thanks for your help