Change text entry via script?

Hi I try to use Keyboard Maestro to get the string: "[3+4+2+5]/16" by typing "3 4 2 5, 16"
The idea is that I have a text prompt when using the macro and KM is reformatting it.
Is this possible? The comma can be a different or no sign.

Hi Frank
This would require a few steps in keyboard maestro alone. I have added a shell script which should do what you want. I have it assigned to the Z key, change it to whatever you want. I replace your clipboard with the new value.

See attached: FrankG.kmmacros (3.6 KB)

read -r input_string

# Replace any non-numeric characters with a space
input_string=$(echo $input_string | sed 's/[^0-9]/ /g')

# Remove leading and trailing spaces
input_string=$(echo $input_string | sed 's/^ *//;s/ *$//')

last_number=$(echo $input_string | awk '{print $NF}')
formatted_string=$(echo $input_string | awk '{$NF=""; print $0}' | tr ' ' '+' | sed 's/+$//')

final_expression="[$formatted_string]/$last_number"

# Print the final expression
echo "[$formatted_string]/$last_number"

demo

Hi Douglas, Wow, this is fantastic! Thanks a lot!