While running KM script via python, how can I send the parameter to it?
1 Like
Thanks Tom. How can I access that variable in KM?
Also, is there a way to pass multiple parameters?
Via the %TriggerValue%
token. See KM Wiki.
Yes, you can format the parameter as array (comma as separator) and then access it through a variable. Like this:
Macro:
[demo] Macro with Multiple Parameters.kmmacros (2.9 KB)
The Python script with the trigger:
#! /usr/bin/env python
import os
os.system("""osascript -e 'tell application "Keyboard Maestro Engine" to do script "3A397B5C-16C1-4D9F-96EF-AE6824718C67" with parameter "first parameter,second parameter,third parameter"'""")
The result:
2 Likes
Thanks Tom for such a detailed explanation.
How can I escape the comma if the value has the comma in it?
You can use a different separator by placing it after the ] and before the percent. Comma is the default. So you can use “#KMSEP#” as the separator in the script (instead of “,”), and then use %Variable%zzzParameter[1]#KMSEP#%
in the action.
3 Likes