Mac: how to close the app after xxx time of inactivity?

Hi,
there’s a way to autoclose the app on a Mac after xxx time of inactivity ?

I’ve added a timer and it close the app after xxx time, but how to detect the timer to run and fire ONLY in case of inactivity ?

Stop the timer in the app‘s activate event, and start it when it deactivates.

https://documentation.xojo.com/api/language/app.htmllication

1 Like

You could add the KeyUp and MouseMove event for the Windows and reset the timer using

timer1.reset

This should effectively reset the timer each time there is a key tap or mouse move.

https://documentation.xojo.com/api/language/timer.html#timer-reset

No. Won‘t work if someone types a long text in a TextArea, or moves through the interface with keyboard controls.

You would have to pass the keyUp event of EVERY control up to the Window for it to work (which would become more involved if some ContainerControls are involved) and is way more processor intensive without any gain.

Preview auto close by itself (but I do not recall how this is done; when there is no open window ?)

I see two possible options here.

The first is to monitor keyboard and mouse events (and possibly others; IIRC inserting disks may also count as an “activity”, and probably others) at the app level. When you get one, you reset the timer.

The other one is simpler, but I don’t know if it’s available outside of Mac OS X. There’s an OS declare available which returns the amount of time since last activity. You may monitor this value and, when it’s changing, reset the timer.

Both methods require either declares or plugins (like the MBS plugin). Do you happen to have bought it?