Execute Macro if app in use, but limit frequency to no more than every 5 minutes

Hi,

So I'm trying to create a macro that:

  1. Executes whenever the Application 'someApplication' 'Activates'
  2. Checks some variable, like lastExecutedDateTime, to see if this wasn't already executed in the last 5 minutes:
    • If False: takes/saves a (new) screenshot of the 'someApplication' window and stores the current date/time in some variable, lastExecutedDateTime
    • If True: does nothing

I'm particularly having issues with step 2, to store / calculate / compare the Date / Time.
Please advise... :pray:t3:

(My goal is simply having 5 minute screenshots of the Application, as long as it's being used / has focus.)

Thank you!

I think something like what I've shared below should do the trick:

Execute upon application activation, only every 5 minuets Macro (v10.2)

Execute upon application activation- only every 5 minuets.kmmacros (4.5 KB)

For simplicity I did the time calculation based on minutes since last midnight, so this will break if the time interval crosses midninght, if this is a problem it can be changed to do a full datetime calculation

Edit: fixed a couple of typos

1 Like

That has a slightly different meaning to me than the first point of yours. So here's my take:

  1. Every 5 minutes check if the app is active
  2. If it is, take the screenshot and file it.
  3. If not active, do nothing.

Here's the macro that illustrates this.

Download Macro(s): Test copy.kmmacros (5.6 KB)

Macro-Image

Keyboard Maestro Export

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 10.15.7
  • Keyboard Maestro v10.2

Note: the If action checks for the Finder app - you'll need to put the name of your target app there.

1 Like

Thank you @Alexander and @tiffle for your replies, i will test them both and that should get me on the right track for sure. I'll reply as soon as i have time and a working solution;

1 nitpick i still need to solve: when i use the app, it can be for short periods of time (to enter data.) So, if the timer only fires every 5 minutes (versus when the app is active / activated) then it's possible you won't get any screenshots for a longer period of time even though the app is being used;

  • Screenshot timer / executed at 00:00, 00:05, 00:10, 00:15
  • App used at: 00:02 until 00:03 and 00:07 until 00:09
  • Result: no screenshots.

That’s a good point that my macro won’t catch.

Hi, @notDavid. If I correctly understand your requirements I think the following macro should work. (I started with @tiffle's macro.)

Download: Application Screenshots at Specified Frequency.kmmacros (28 KB)

Macro-Image


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.1 (23B5067a) PRE-RELEASE SEED SOFTWARE
  • Keyboard Maestro v10.2

I wasn't sure about one requirement...

If an application is activated, and continues to stay in foreground, do you want to capture screenshots at the 5 minute frequency? If so, you can add the trigger that @tiffle had.

1 Like

Thank you all for your input, i managed to use your examples to create something that works. Here is what i ended up using;

(@Alexander i had to adjust your Macro a bit because it saved the variable each time, even if no screenshot was taken, resulting in 0 screenshots for some time.)

Thank you!

App activated screenshot 5 mins.kmmacros (6.1 KB)

1 Like