Redact, redact, redact. … and some “tokenism”

Let me begin by expressing my gratitude to all the techies on this forum who have helped me in the past. I consider myself a power user, but NOT a programmer. I do, however, like to learn something new when I can immediately apply it to the task at hand. Thus, this most recent post.

I have written a rather clunky KM macro to use in PDF Expert for redacting my account numbers from my bank statements, and it seems to work. But I would love to see it get turned into more elegant language. Specifically, I would like to create a loop within this macro that will accomplish the same thing that the macro does already. There are seven separate redactions that it performs on my credit card statement, one for each account number in its various formats. (In some cases, it finds and redacts one number, in others it redacts several occurrences of an account number. Sorry for getting into the weeds.)

Essentially, I would like to have a macro that expresses only once the action to be performed and then perform it on the various account numbers. One caveat: when opening a new document to be redacted, the REDACT function has to be activated before the first FIND. Then a “FIND AND REDACT button needs to be clicked followed by another button, BLACKOUT ALL. Once these actions are performed, all remaining redactions can be done by just clicking the BLACKOUT ALL button (as per the attached macro file, which, I repeat, does work).

  1. Redact the Account numbers - Corp Visa copy Macro (v11.0.3)

1. Redact the Account numbers - Corp Visa copy.kmmacros (196 KB)

Finally, (and this does apply to this post) as I poke around in Keyboard Maestro, I see within the action, INSERT TEXT “” BY PASTING, the phrase, INSERT TOKEN. When I click on that little drop-down I am presented with a plethora of choices, the most obvious one being “VARIABLE”. Boy, oh boy, would I like to learn about tokens! Variables, yes, but TOKENS! What are these magical things? I know they have to do with loops and things like that, but I am afraid I have forgotten most of my algebra. Sorry, please don’t laugh (by the way, I am 74).

Once again, I am always very grateful for the help I have received on this forum. And many thanks ahead of time for this one. I know that I will be able to apply to future situations what I learn here in this post.

I'm sure some of the experts on this site are close to your age. They probably have a long history with programming.

It seems to me that you have mastered doing something multiple times, but you just want to understand how to adjust your code to use it in a loop. Sure!

There are multiple different ways to create loops. I'll mention one way. Other people might have other ways. Here's how I would do it in your case. Notice that I placed each number into a loop edit box and then reference that value using "%Variable%LocalEachNumber% inside your Insert Text action. I think that should work, but bear in mind that I didn't test the code, (and I don't have PDF Expert anyway) so you may have to try it to validate that my code works.

image

No magic -- just a quicker way of saying "placeholder for something that will be included when this bit of the macro is executed". Usually (but not always) that "something" is changeable and you use the token to get "current information".

You could, for example, keep a record of interesting web pages visited in Notes with the date, time, and URL of the page. For each page you would type:

10 October 2024 at 10:23 -- https://www.google.com
10 October 2024 at 10:25 -- https://www.bbc.co.uk
...

...which is a lot of boring typing, checking what the date is, looking up to find the current time, and so on. So you get KM to do the work for you:

image

The tokens in the action are evaluated when the action executes, %ShortDate% is replaced with the current date in your system's "short format", and so on.

The %Variable% text token is the same -- but instead of being replaced by the current date or time or whatever, it is replaced by the value stored in the variable named in the token. So if you set the variable MyVariable to "fish fingers":

image

...you can use it later in your macro:

image

...which will type out

This week I will be mainly eating fish fingers.

...when the macro is executed.

Note that the above is not good practice! Give your variables meaningful names so you know what they are there for, and "scope" them as tightly as you can so your different macros don't interfere with each others' variables and change values when you don't expect it. There's more about "scope" in the manual, and the rules on naming are just before that.