Attempt to Pass FileMaker Cell to KM Then Pass Variable Back Into FMP (KM_8.2.4)

Attempt to pass FileMaker cell to KM then pass variable back into FMP Keyboard Maestro 8.2.4

First time post...

Attempting to pass a FileMaker cell to KM then pass a variable back into FMP from KM.

Attached below is my KM Macro I'm working on...

A) To simplify my issue before posting to this forum, I've reduced my variable to only one cell in FileMaker (A cell holding the lastname of the person's record). The goal is to get FMPCell assigned to AppleScriptVariable that gets assigned to KeyboardMaestroVariable. I've managed to successfully write a script within FileMaker Pro Advanced v16 to:

  1. Set AppleScriptVariable to the value of specified field/cell in FileMaker.

  2. Then within that same script, assign KeyboardMaestroVariable to the AppleScriptVariable value.

FileMaker Script step - Perform AppleScript (Native AppleScript):

-- Set ApplScr Variable from FMP Field

set FMName to "FileMaker Pro Advanced"

tell application FMName

—FOLLOWING FORMAT: set AppleScriptVariable to cell named "FileMakerDatabaseName::FileMakerFieldName" of current record as text

set AppleScriptVariable to cell named "Support FM 55::last" of current record as text

end tell

-- Set KM Variable from ApplScr Variable

-- ignoring application responses

tell application "Keyboard Maestro Engine"

setvariable "KMVariable" to AppleScriptVariable

do script "69CA446B-8892-43D2-94A5-5A30413269CE"

-- or: do script "FMP KM and AppleScript"

-- or: do script "69CA446B-8892-43D2-94A5-5A30413269CE" with parameter "Whatever"

end tell

-- end ignoring

When I run the script from within FileMaker, it assigns the variables and triggers the desired KM Macro.

The KM Macro does its steps. For this simplified example, I have a macro step that updates the KMVariable (ie: as if the KMVariable became "NewValue")

My goal (which I cannot figure out): I NEED to set cell named "Support FM 55::last" of current record (in FileMaker) to the NEW value stored in KMVariable and have it pushed automatically back to the cell in FileMaker.

The closest I've come to a solution is a KM action: Executing AppleScript where it assigns the FMP cell to a text string (BUT I need it to be a variable instead of a fixed text string):

set cell named "Support FM 55::last" of current record to "CanOnlyAssignText"

I want this to work:

set cell named "Support FM 55::last" of current record to AppleScriptVariable

-or-

set cell named "Support FM 55::last" of current record to value of variable "KMVariable"

but neither work.

B) Related, but separate problem... With my current KM Macro, if I select the tasks and click "Try Actions" then my script (the FMP cell "Support FM 55::last" updates to "CanOnlyAssignText") appears as if it is working. But when I run the script from within FileMaker, then the KM Macro works up until it stalling out during the Execute AppleScript step: tell application "FileMaker Pro Advanced"... At that point when hover your cursor over the FileMaker application, you get the spinning beach ball. Two minutes later, it breaks free and FileMaker pops up a display window with the error message:

Keyboard Maestro Engine got an error: AppleEvent Timed Out. (-1712)

I have been learning a lot from this forum browsing through, but I’m stuck and could use your expertise!

Thank you in advance.

-Howard

Tags: Variables, applescript, help, file_maker_pro, filemaker, FMP

FMP KM and AppleScript.kmmacros (7.5 KB)

For the part "(which I cannot figure out)"

Do both of these from within FMP.

First set the AS Variable from the KM Variable:

-- SET AS VARIABLE FROM KM VARIABLE
tell application "Keyboard Maestro Engine"
   set ASVariable to value of variable "KMVariable"
end tell

Then set the FMP field from the AS Variable:

-- FMP FIELD FROM AS VARIABLE OR TEXT
tell application "FileMaker Pro Advanced"
   set cell named "VariableField" of current record to "YO" (or use ASVariable - no quotes)
end tell
1 Like

ah!, well I took a look at your script, which I should have done first!!!

take the hyphens out of the lines to ignore the application responses. (below)
I had this in the beginning of using KM and it drove me batty!
I ran your script with success.

ignoring application responses
tell application "Keyboard Maestro Engine"
do script "69CA446B-8892-43D2-94A5-5A30413269CE"
-- or: do script "FMP KM and AppleScript ORIG"
-- or: do script "69CA446B-8892-43D2-94A5-5A30413269CE" with parameter "Whatever"
end tell
end ignoring

@troy setting the field from an Apple Script Variable does not work for me within FMP.

I'll get a FileMaker popup window with error message: "The variable AppleScriptVariable is not defined." Unknown Error: -2753.

In a separate script in FMP, I've got these steps:

tell application "FileMaker Pro Advanced"
activate
delay 1
set cell named "Support FM 55::last" of current record to AppleScriptVariable
— set cell named "Support FM 55::last" of current record to "CanOnlyAssignText"
end tell

I am not able to set the "FMPVariableField" to an AppleScriptVariable, but I am able to set it to a string of text without getting an error (which is not my actual desire), using this line:
set cell named "Support FM 55::last" of current record to "CanOnlyAssignText"

As for the "ignoring application responses"... "end ignoring", that is in the other FMP script that is calling KM and assigning the AS variables and KM variables, which is working fine for me, even though they are hyphened out.
But then once KM modifies and resets the KM variable and assigns its value to the correlating AS variable (AppleScriptVariable), I need to get that AS variable back into the FMP cell. So I have to either do that within the KM macro, or within a different separate FMP script that says "The variable AppleScriptVariable is not defined."

@troy I am wrong. You are correct! I forgot to assign the KM variable to the AS variable. And that is all it took. It is working! You are my hero! Thanks!

1 Like