I have a python script that works with a file name but not when I replace the file name with the Keyboard Maestro variable $KMVAR_fName. When I use $KMVAR_fName it reports in the Engine.log
FileNotFoundError: [Errno 2] No such file or directory: '$KMVAR_fName'. Macro “Trying” cancelled (while executing Execute Shell Script).
I've cut and pasted the file name that works into Keyboard Maestro variable fName and it still reports "no such file".
Here is the python code.
#!/usr/bin/env python3
# encoding: utf-8
def check(token):
with open("$KMVAR_fName") as f:
datafile = f.readlines()
for line in datafile:
if token in line:
return line.partition("Subatomic: ")[2]
return False # Because you finished the search without finding
# Use
output = (f'\t\t- {check("Subatomic: ")}')
print(output)
This is the file name I'm using for testing and is 'fName'.
/Users/will/Dropbox/zettelkasten/Creative Pressure 202201051306.md
Here is how I'm using this in Keyboard Maestro. Down near the bottom.
Since you reference a python file which is already on disc, then KM does not intepret the variables inside this file.
You could have an action before writing the python file to disc and then execute it. When writing the text to disc KM will replace the variable with the filename.
I do something similar automating some things with Adobe InDesign.