Restart KM Engine if Conditions are Met and no other Macros are Running

Probably a niche case macro.

KM Engine: Relaunch Conditionally [0.9.4].kmmacros (74.5 KB)

Aperçu

Background:

I am using a couple of macros in a game, most of them triggered by movement keys and mouse button down/up events (via USB Device Key Triggers) and then sending other keys, i.e. they are triggered very often, like 30 times or more per minute.

I noticed an increasing lag sometimes with these macros, and also with other macros, when the KM Engine was up for quite a while with such load.

Restarting the KM Engine always helped/helps.

Hence this macro:

  • It automatically (adapt the triggers to your needs!) or manually (Status Menu) relaunches your KM Engine.
  • You can set the interval to restart the Engine (e.g. every 8 hours). The interval acts as a minimum uptime for restarting and is checked against the process age, so if the engine was restarted by other means, it will be taken into account.
  • It has a Display Only mode, to just show the process age, in case you are curious.
  • It has a Force mode, to manually restart the engine no matter the uptime.
  • It checks for running other macros before quitting the engine, and retries a number of times if running macros are found. (See the in-macro documentation for details and the number of retries / delay config.)

The triggers of the macro as posted (Wake, Idle, Periodic, Status Menu), are suggestions. It depends on your setup and habits what kind of and what trigger(s) you want to use.


Edit:

  • Jul 9, 2024
    • Improved the description.
  • Jul 7, 2024
    • Uploaded a more meaningful macro image.

Peter advised us not to use the kill command.

I am quitting the engine via AS, no? pkill -kill comes into play only when 3 quit attempts failed.

tell application id kmEngine to quit

Ok sorry. I guess that's reasonable. I jumped the gun, and I'm feeling bad about that. I just saw a "kill" statement and made my comment.

No prob, thanks for having a look at the code, you may discover other flaws :wink:

1 Like