I’d like to be able to trigger a KBM key from AppleScript.
Also be able to set an AppleScript var from KBM
And lastly be able to set a KBM var from AppleScript
any help would be appreciated.
The equivalent Quickeys code is below.
|| Play QK –
tell Application "quickeys"
play Shortcut Named "xxx"
end Tell
|| set AS Var from QKs –
tell application "QuicKeys"
set ASVariable to the value of variable named "V01"
end tell
|| set QK Var from AS–
tell application "QuicKeys"
set value of the variable named “xxx” to VAptCostPreTax
end tell
In each macro, the code to execute from AppleScript is available from the “Or by Script” trigger option.
You can’t set an AppleScript variable from outside of the AppleScript. An AppleScript can read or write a Keyboard Maestro variable as described in the Variables section on the wiki.
You can "type" keys from AppleScript using keystroke and key code, but to trigger a KM macro, it would be best to trigger using the Macro UUID, like this:
As @peternlewis suggested, get the AppleScript from the "Or by Script" trigger option. Just click on it and you will see:
The UUID is used in the first example code provided.
You can NOT set an AppleScript variable from KM, but it is very easy to set an AppleScript variable to a KM Variable in a script:
tell application "Keyboard Maestro Engine" to set yourASName to getvariable "yourKMVarName"
Setting a KM variariable is just as easy:
tell application "Keyboard Maestro Engine"
-- IF Variable does NOT exist, it will be created --
setvariable "yourKMVarName" to yourASVarName
end tell
Of course, you put both of these AppleScripts in a KM Action "Execute AppleScript".
I have a “display test” in the global macro group.
It runs if I click on it on the global palette.
It runs from Script Editor (AS native app")
but it doesn’t run from within FMP, I made it a single line of code
In Filemaker Pro -
Perform Applescript
with the following
– ignoring application responses
tell application "Keyboard Maestro Engine"
do script “23D9A5D8-FB30-4032-8B18-A35D971AE4B7”
– or: do script “z AS Postings”
– or: do script “23D9A5D8-FB30-4032-8B18-A35D971AE4B7” with parameter "Whatever"
end tell
– end ignoring
filemaker pro 15,
and an AppleScript dialog displays correctly from within FMP,
so AS is running fine, and I can trigger keys in other apps.
run the KBM key and it chokes, spinning wheel and then ‘releases’, never running the key
thanx
Upon further investigation -
From FMP I am calling a macro that has an AppleScript in it running back to FMP.
This worked in quickeys.
It does not in KBM.
So is it true that you can’t run an AS from an app. that calls a KBM macro that runs another AS? - that seems weird, no?
The old code should still be correct - it is the AppleScripty way of doing things. But you’re right, it should include the newer setvariable/getvariable method because, despite (or because) not being AppleScripy, it is much easier to use.
Basically, if FMP is locked up executing your AppleScript, then it will not be available to respond to your AppleScript. This is one of the reasons that Keyboard Maestro executes AppleScripts via osascript.