Increment Selected Numbers (like in VIM) in an HTML TextField

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)

Macro screenshot

Macro notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System information
  • macOS 14.4.1
  • Keyboard Maestro v11.0.2


Thank you.

  1. Didn't know I could increment like that directly
  2. it should be %SystemClipboard%

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:

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.


Im on KM 10.2
It does not seem to have the With Format field

I tried this but didn't work
Screenshot 2024-04-19 at 9.02.50 AM

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.


My Mistake.
You are right.
The Option is there in 10.2

Thanks for all the Help