Lua primitives: on_idle()
If you define the function on_idle it will be called approximately once a second when the the client is idle.
function on_idle() msg( "The client is idle " .. os.date() ); end
By default on_idle will be invoked too regularly to sync your email from a remote source with imapsync, getmail, etc.
But using this function you can schedule regular tasks. For example the following will execute imapsync approximately once every five minutes:
do -- last sync time. local ls = os.time() function on_idle() -- get current time ct = os.time() if ( ( ct - ls ) >= ( 60 * 5 ) ) then ls = ct os.execute( "imapsync" ); end -- now handle the normal on_idle stuff.. end end
This function has been available since version 0.07.