Tips: Show Examples of How KM8's New Features Have Improved Your Macros/Workflow

Continuing the discussion from KM8: A Few Miscellaneous Bugs:

I've been wondering about this since launch, but have no impressive examples myself. I've been able to drop macros like [KM] Put Selected Actions into Group Action in favor of the new Engroup feature, etc., but I'd like to see what improvements y'all have made. :slight_smile:

I don't have any macros to post yet, but here are a few of the new features that I find very helpful:

Front_Browser Actions & Functions (KM Wiki)

  • These greatly simplify macros where you want to support both Safari and Chrome

Local and Instance variables

  • These will help insure that variables are used/set only where they are intended to be used, and to greatly reduce the variable clutter caused by Global Variables.
  • I expect to rewrite many of my macros using these.
  • However, I'm waiting for the new prefix character to be established, and I also hope that two underscores will be supported in addition to a space in the prefixes, as in "Local__" and "Instance__"

The New "Always Activated and ..." Option for Macro Groups:

.

  • This is really huge, and makes use of Palettes, IMO, much much more powerful.
  • We can now have BOTH:
    • Individual Macros always active and can be triggered any time
    • Show a Palette for the same Macro group when we need it.
  • For example:
    .

    .
    (Note to @peternlewis: is this new feature documented anywhere in the Wiki? I couldn't find it.)

And I am sure there will be many more. That's all for now. :wink:

2 Likes

All right, here's the best (read: only, at least for now) example I have to share. Background: a few months ago, I made a thread asking for help with a date converter macro, which in turn led to this thread where Peter teased an upcoming KM8 improvement that promised to make this surprisingly tricky task considerably simpler. Now that KM8 is here, I was finally able to take a crack at streamlining it and seeing how much simpler I could make it (spoiler: quite a lot simpler).

To illustrate, here's the original, KM7 macro:

And here's the newly KM8-optimized macro:

(download for anyone interested) KM8-Optimized JP Dates → US Dates.kmmacros (5.7 KB)

To put that in number form, the original macro used 25 actions and 4 variables altogether, and the KM8-optimized one uses 9 actions and zero variables. The new version achieves this entirely thanks to KM8's ability to use regex matches and capture groups in tandem with the %Calculate% token, especially the new %CalculateFormat% token (without which the date conversions couldn't be formatted properly). These new abilities also completely eliminate the need for the original's For Each loops and variable "placeholders" (which were used in the original version to ensure that only one matching pattern at a time was used for calculation and replacing) as the necessary calculations can now be searched, done in-place, and written back en-masse.

I doubt this particular macro will be very useful for anyone who doesn't regularly work with Japanese dates, but hopefully this helps show what KM8 makes possible :slightly_smiling_face:

2 Likes

Not that it matters, but I think this was already possible with KM7. IIRC.

Quoting myself…

It seems my “IIRC” was wrong. Can’t make it work with KM7. Must have mixed it up with some other thing.

And, before you ask: Yes, I still have one Mac with KM7 running. Shame one me. But the sole purpose of that KM7 Mac is to verify whether something I perceive as new with KM8 really is new. Or vice versa :wink:

Here is an example of mine how I used the new KM8 features in a macro:

Macros for Retina Screenshots on the Forum

  • The macros are exclusively using local and instance variables
  • Since some of the macros are executing another macro, it may serve as a demo where to use instance variables and where to use local variables.
  • One of the macros also uses a Calculation token in a regex replacement (apparently without me knowing that this didn't work before ;))
  • The new operators of the If…Then action (for example "<=") are used.
1 Like

Version 7 would process the tokens of the replacement, but only once before the search & replace started.

Version 8 processes the token for each replace, allowing you to use the results of the match as part of the replacement, changing the replacement each time.

1 Like

I wrote two small macros utilizing KM8's scripting support.

One more small improvement.

Now as you’re mentioning it, I also wrote one with KM8’s new AppleScript classes:

1 Like

Was able to drastically pare down and improve a macro I came up with a few months ago for searching text files and displaying results thanks to Prompt With List:

2 Likes

Still haven‘t tried the List Prompt. Thanks for the reminder.

1 Like