Calc macro deactivate and Close Application

I need a macro to run when I leave LO running and switch to another app which is open on my Ima (MacOS Mojave).

As far as I can discover, Deactivate only works when I switch to another LO window, not when I switch to another app (e.g. my browser), leaving LO running in the background.

The other option I’ve tried is Close Application, but that only fires when I close LO.

Is it possible to have a macro run when I leave LO running and switch to another app i.e. LO loses focus?

Thanks for all your help

I’m all but an expert, but would assume:
Switching between applications isn’t an event handled by any of these applications, but by the OperatingSystem. You will need to listen to OS events.