Idle timeout on Mac

Is there a way to quit the Xojo desktop app when computer is idle for specified period of time (such as 15 minutes)?

Create a global Date variable and whenever there is user activity, set it to the current date and time. Also have a Timer that fires each minute that checks if this global Date variable is > XX minutes from the current date and time — if so, then quit.

Will do, thanks.