About the shell script wiki – does this rule still work?
"Keyboard Maestro sets the environment variables for the script to include all your variables, using a prefix of KMVAR_ and your variable name with spaces changed in to underscores (_). For example, your Keyboard Maestro “File Name” variable will be available as the environment variable KMVAR_File_Name ."
I find that it's not working if the KM variable has spaces:
It's failing because you are passing in a ~ path from your variable, and the ~ prefix doesn't expand to your home folder path when it is quoted. But you can use a "Filter" action set to "Expand Tilde" to get a full path to pass to the script. Try this example, first with the second action disabled, then with it enabled, to see what I mean:
Nice improvement on the shell script. Here's what I'd got to before you posted (note the use of a Local variable in KM, something you should consider unless you want the value to persist or be available to other macros):
#!/bin/bash
cd "$KMVAR_Local__image_folder"
i=1
for file in *
do
mv "$file" "$i.${file##*.}"
((i=i+1))
done