Stopping Mac going to Sleep

The code available on my site http://www.ohanaware.com/xojo/ creates a ‘token’ when you enable the mode, so that when your routine has finished the token automatically gets released.

If you want to hold onto the token, simply do what Christophe does and stuff it in a variable on the window or in the app. It’s advisable to release the token when your application no longer needs to keep the machine awake, i.e. it’s finished it’s processing.