Read URL and Smart Counter

I have thousands of URL's to visit and edit. All of them are in sequential order. For example..., etc.

The URL is always the same, except for the numerical part that designates the product ID.

Currently, I have it setup to count from 0-100 using a series of 20 macros (10 macros count from page 0 to page 9, and 10 other macros count the 10's. i.e. once page 9 is done, it moves to the macro that starts on page 10, and then repeats the 0-9 process. Hopefully this makes sense so far.

Once I reach page 100, I need a way to work through the 100's. In other words, if I run my series of macros starting at 20,000, it will end at 20,099.

The question is, can I make a macro that knows which 100's to roll over to depending on what number it's currently at? Is it possible to make a macro that contains a bunch of if/then statements?

if last 3 digits = 099, then replace the 0 with a 1
if last 3 digits = 199, then replace the 1 with a 2, etc.

I'm not sure if Keyboard Maestro can do something like this. If so, any help would be very appreciated.


Update: a better alternative might be to make one macro that includes a sequential counter that I can use to update the URL. Is something like that possible?

Yes, a single macro is definitely possible, and more than enough for a use case like this. If I understand you correctly, you want a macro that will go to the next product ID URL incrementing by one each time you run the macro? This should get you started:

Example Macro.kmmacros (3.0 KB)

If you want to edit the Counter variable later to start at a different number, the easiest way to do that is probably to edit it directly in KM's preferences, under the Variables pane:

1 Like

That's exactly what I'm looking for. Thank you very much. I was just going to update the post to mention that I got something working as well. Definitely not as elegant as yours, but it's getting the job done. It's activating Chrome, selecting the URL, left-arrowing to the ID, copying, adding 1, and pasting over the old ID. I'm going to incorporate your version. It's much cleaner.

Screen Shot 2020-05-19 at 10.16.03 AM

On a side note, I usually add small delays between actions so that macros don't get ahead of themselves. Are there any hardfast rules as to when delays are unnecessary?

1 Like

Glad to hear my example was useful🙂

In response to your last question, delays are generally only really necessary when a macro is simulating UI actions, like mouse clicks and keystrokes. Macros that solely use programmatic actions, like variable and clipboard manipulation, should always execute smoothly in succession, and never require a delay.