Time of last access to application

Hello!

I have a macro to switch to the WhatsApp application. To avoid going there too often I have added a prompt, which asks, if I really want to open it now, when it is closed. Now what I am missing is to close it automatically after set time when I am not using it.

I know I can trigger a macro every few minutes when an application is running, but I don’t want it to close when I am actually using it. So I’d like to add a check to see, whether it hasn’t been active (the front window) in the last 5 minutes or so.

Any ideas? KM, Apple Script, Commandline… Anything would be fine :slight_smile:

Thanks!

Hi Sandro,

This is certainly doable within KM, though it does require two separate global macros to accomplish. The first step is to set up a macro that is triggered by WhatsApp deactivating (i.e. no longer being the frontmost app) and have that macro set a variable to the current time:

(I've used Finder here instead of WhatsApp because I don't have WhatsApp installed on my system, but the rest can be used as-is)

Next, you need a macro that is triggered periodically (this can be done either with the periodic trigger or the new-to-KM8 cron trigger) to check the WhatsApp timestamp variable against the current time and quit the app if more than 5 minutes have passed:

(again, I didn't use WhatsApp because I don't have it installed, so of course you'll want to change the Quit Application action to quit WhatsApp rather than the front app)

One key thing about these macros is that they must be global, i.e. in the Global Macro Group or any other macro group that is always activated and available in all applications, otherwise they may not function as expected.

Anyway, this ought to get you started, but feel free to ask any follow-up questions if anything is unclear :slightly_smiling_face:

Oh yeah, that got me going. Thanks a lot! :slight_smile:

I was missing the idea of triggering something when the application deactivates...

I had to finetune a bit though, to avoid accidential quitting. Here is what I ended up with

  1. To set/reset the variable

  2. The Periodic Check

The problem was, that the leaving timestamp remained after WhatsApp was quit. So when reopening it the next time, I would have had to leave it before everything was set again.

Thanks again!

Sandro

1 Like