The behaviour your describe is consistent with an idle event which monitors InDesign idleness. Once the event listener is thrown and as long as no manual operations are done, the timer resets to 0 and starts counting.
If you had a script that would create a frame on such an event and given you don't touch indesign , it will do for ever every 5 seconds.
If you need to stop it after first execution, you need to set its sleep delay to 0 or remove the listener.
Actually my goal later is to set Indesign to export JPG-files of all the pages in a document when I'm not working with InDesign (lets say idling for 10 minutes). When I tried this script it does the script every 5 sec even if I'm am working (manually) in Indesign. What conditions makes InDesign in idle mode if making new elements and move them around on the page does not?
Actually the confusion was shared. Looking at the doc a second time:
InDesign’s idle tasks execute when there are no events in the event queue for the application to process. It
is easy to run idle tasks by scripting. The onIdle event provides a way to run scripting-based idle tasks. It
can be used to automatically execute a script when InDesign/InCopy is idle. Its event target is IdleTask,
and its event object is IdleEvent.
The sleep property of the idle task is the amount of time that elapses before InDesign calls the task again.
It should be obvious that you need to set the sleep time to a value high enough that it does not interfere
with your work, though this value will vary depending on what tasks the script performs.
Actually, I think it's not what you do or don't inside indesign but there is nothing to proceed as stated in the very first line.
So, if I understand this correct - the sleep property just tells indesign to delay 5 sec before running the script, rather than run the script only if the application has been idling in 5 sec?
No I don't think so. What i understand myself is that as soon every events have been processed, the delays starts counting. If an external event occurs in the meanwhile, the counter resets. Your listener may not have been fired then. If no events occur, the delay may reach its end and fire your listener. So the counter resets and etc.
But it's mostly all I can tell about this topic. Every time I used idleEvents, I used it with small delays and I wanted them not to be ceased.