I want to create a macro that will increment the Selected number in a text field everytime a hotkey is pressed
I tried to find the number with regex but it is not working.
Any help ?
I want to create a macro that will increment the Selected number in a text field everytime a hotkey is pressed
I tried to find the number with regex but it is not working.
Any help ?
You shouldn't have to do any regex work—Keyboard Maestro can recognize numbers. This macro works for me in TextEdit:
Download Macro(s): increment number.kmmacros (2.9 KB)
-rob.
Thank you.
The macro is working, but I would like to add a Zero padding using Format "%03d". Could you show how ?
Keyboard Maestro's help is context sensitive and very well done. Click the gear icon next to the Set Variable to Calculation action and select Help, and you'll go here:
https://wiki.keyboardmaestro.com/action/Set_Variable_to_Calculation
In there, it notes that you can optionally format the result, using the Gear menu: You'll see a Format Result entry there; select it, and the action gains a new field. But you can't use Unix-style %03d
formats. Instead, as linked on the help page, you need to use Unicode number format strings.
For a three-digit padded-zero no-decimal format, you'd use 000
. So the final action would look like this:
Note: This doesn't apply in this case, but be careful with formatted numbers. If the format includes non-numeric characters, even including the comma, then it will fail if you try to use it in future calculations. If you need to both format a number for display and use it in further calculations, you need to copy the variable to a "display use only" version that has the proper format.
-rob.
Thanks.
Im on KM 10.2
It does not seem to have the With Format field
I tried this but didn't work
Finally resorted to an Execute Shell Script action to run this ruby code
#!/usr/bin/env ruby
original_number = ENV['KMVAR_decrementedNumber'].to_i
padded_number = original_number.to_s.rjust(3, '0') # Pad the number
puts padded_number
It will if you click the blue gear icon and select the Format Result option—I'm 99% positive that was there in 10.
-rob.
My Mistake.
You are right.
The Option is there in 10.2
Thanks for all the Help