Capture the last time code (for a given event type) in a log file

I was thinking about the machine’s time.
I am really slow at building macros so my time is anyways flying away, haha!

Well, if you want to have hours, minutes, seconds, frames saved to separate variables you are going to have to do some form of processing whatever the method. We’re not talking about processing vast amounts of data here - just some lines of text. So, my guess is the method won’t make any noticeable difference to your overall task. I suppose try it and see.

I guess this also.
I always have this idea that I should make the macro as short/simple, i.e. as few steps/actions, as possible. But it makes good sense not always getting too caught up in this idea!

Yes, that is a good aim. One of the great things about Keyboard Maestro is that once you have a Macro that works and does what you want, if you find a better way at a future date to do some part of it you can always make a new version to use that method instead.

Also, if you have a series of Actions that essentially do one task you can multiple select them, Engroup them in a Group Action, rename that Group to something that explains the task and then collapse the Group so you don't have to view all the separate Actions.

Actions>Engroup>Group

1 Like

This simple regex will do the trick:
image

2 Likes

Thank you! The (?m) and the (?s:.*) is doing some magic here I do not understand yet, but it’s working!

In the interest of learning regex slightly better I am fiddling a little with this approach now. By moving the last parenticis before App Starting I am able to capture only the timecode part of the line:

(?m)(?s:.*)(^.+)App Starting

But am I right in thinking that I'd have to run a separate action here to capture the individual datetime elements into separate variables to run a Time()-calculation? (Using (\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+) like the Macro Image below shows.) Or could it be possible doing this all in one line of regex?

The (?m) works with the ^ to indicate the input variable consists of multiple lines and to start matching at the beginning of each separate line instead of the entire string.

The (?s:.*) gets the last match.

You can match each date component separately in one regex. See screenshot.
image

1 Like

Thank you so much for this explanation! And wow, this amazing do-it-all line of regex!

This is exactly what I was setting out in hopes to find when first creating this thread, and it's amazing to now see it actually existing and working.

As a wonderful bonus this thread have given me other angles to tackle this problem from, and through this I've gained important further insights into KM as a whole. Thank you all so much for this!

1 Like